-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifest_test.go
65 lines (61 loc) · 1.43 KB
/
manifest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"bytes"
"github.com/stretchr/testify/assert"
"testing"
)
const (
testManifest = `
version: 2
default:
check:
path: /hello
resource:
cpu: 200:2000
vars:
hello: world
hello2: world
build:
- echo hello {{.Env.WORLD}}
package:
- FROM nginx
- RUN echo {{.Vars.hello}} > /usr/share/nginx/html/index.html
- RUN echo {{stringsToUpper .Vars.hello2}} > /usr/share/nginx/html/index2.html
dev:
check:
port: 8888
resource:
mem: 200:-
vars:
hello2: world2
build:
- echo hello2 {{.Env.WORLD}}
`
testManifestBuild = `#!/bin/bash
set -eux
echo hello2`
testManifestPackage = `FROM nginx
RUN echo world > /usr/share/nginx/html/index.html
RUN echo WORLD2 > /usr/share/nginx/html/index2.html`
)
func TestLoadManifestFile(t *testing.T) {
var m Manifest
var p Profile
var err error
err = LoadManifest([]byte(testManifest), &m)
assert.NoError(t, err)
p, err = m.Profile("dev")
assert.NoError(t, err)
assert.Equal(t, "dev", p.Profile)
assert.Equal(t, 8888, p.Check.Port)
assert.Equal(t, "/hello", p.Check.Path)
assert.Equal(t, "200:-", p.Resource.MEM.String())
assert.Equal(t, "200:2000", p.Resource.CPU.String())
var buf []byte
buf, err = p.GenerateBuild()
assert.NoError(t, err)
assert.Equal(t, []byte(testManifestBuild), bytes.TrimSpace(buf))
buf, err = p.GeneratePackage()
assert.NoError(t, err)
assert.Equal(t, []byte(testManifestPackage), bytes.TrimSpace(buf))
}