-
Notifications
You must be signed in to change notification settings - Fork 51
/
config_test.go
64 lines (51 loc) · 1.95 KB
/
config_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
package captain // import "github.com/harbur/captain"
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
var basedir, _ = os.Getwd()
func TestConfigFiles(t *testing.T) {
c := configFile("captain.yml")
sl := "captain.yml"
assert.Equal(t, sl, c, "Should return possible config files")
}
func TestReadConfig(t *testing.T) {
c := readConfig(configFile(basedir + "/test/Simple/captain.yml"))
assert.NotNil(t, c, "Should return configuration")
}
func TestNewConfig(t *testing.T) {
info("cwd %s", basedir)
c := NewConfig("", basedir+"/test/Simple/captain.yml", false)
assert.NotNil(t, c, "Should return captain.yml configuration")
}
func TestNewConfigInferringValues(t *testing.T) {
c := NewConfig("", basedir+"/test/noCaptainYML/captain.yml", false)
assert.NotNil(t, c, "Should return infered configuration")
}
func TestFilterConfigEmpty(t *testing.T) {
c := NewConfig("", basedir+"/test/Simple/captain.yml", false)
assert.Equal(t, 2, len(c.GetApps()), "Should return 2 apps")
res := c.FilterConfig("")
assert.True(t, res, "Should return true")
assert.Equal(t, 2, len(c.GetApps()), "Should return 2 apps")
}
func TestFilterConfigNonExistent(t *testing.T) {
c := NewConfig("", basedir+"/test/Simple/captain.yml", false)
assert.Equal(t, 2, len(c.GetApps()), "Should return 2 apps")
res := c.FilterConfig("nonexistent")
assert.False(t, res, "Should return false")
assert.Equal(t, 0, len(c.GetApps()), "Should return 0 apps")
}
func TestFilterConfigWeb(t *testing.T) {
c := NewConfig("", basedir+"/test/Simple/captain.yml", false)
assert.Equal(t, 2, len(c.GetApps()), "Should return 2 apps")
c.FilterConfig("web")
assert.Equal(t, 1, len(c.GetApps()), "Should return 1 app")
assert.Equal(t, "Dockerfile", c.GetApp("web").Build, "Should return web Build field")
}
func TestGetApp(t *testing.T) {
c := NewConfig("", basedir+"/test/Simple/captain.yml", false)
app := c.GetApp("web")
assert.Equal(t, "harbur/test_web", app.Image, "Should return web image")
}