forked from marpaia/chef-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment_test.go
93 lines (85 loc) · 2.18 KB
/
environment_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package chef
import (
"testing"
)
func TestGetEnvironments(t *testing.T) {
chef := testConnectionWrapper(t)
config := testConfig()
environments, err := chef.GetEnvironments()
if err != nil {
t.Error(err)
}
if environments[config.RequiredEnvironment.Name] == "" {
t.Error("Required environment not found")
}
}
func TestGetEnvironment(t *testing.T) {
chef := testConnectionWrapper(t)
config := testConfig()
_, ok, err := chef.GetEnvironment(config.RequiredEnvironment.Name)
if !ok {
t.Error("Couldn't find required environment")
}
if err != nil {
t.Error(err)
}
}
func TestGetEnvironmentCookbooks(t *testing.T) {
chef := testConnectionWrapper(t)
config := testConfig()
_, err := chef.GetEnvironmentCookbooks(config.RequiredEnvironment.Name)
if err != nil {
t.Error(err)
}
}
func TestGetEnvironmentCookbook(t *testing.T) {
chef := testConnectionWrapper(t)
config := testConfig()
_, ok, err := chef.GetEnvironmentCookbook(config.RequiredEnvironment.Name, config.RequiredCookbook.Name)
if !ok {
t.Error("Couldn't find cookbook in environment")
}
if err != nil {
t.Error(err)
}
}
func TestGetEnvironmentNodes(t *testing.T) {
chef := testConnectionWrapper(t)
config := testConfig()
_, err := chef.GetEnvironmentNodes(config.RequiredEnvironment.Name)
if err != nil {
t.Error(err)
}
}
func TestGetEnvironmentRecipes(t *testing.T) {
chef := testConnectionWrapper(t)
config := testConfig()
recipes, err := chef.GetEnvironmentRecipes(config.RequiredEnvironment.Name)
if err != nil {
t.Error(err)
}
found := false
for _, recipe := range recipes {
if recipe == config.RequiredRecipe.Name {
found = true
}
}
if !found {
t.Error("Couldn't find required recipe")
}
}
// For now I am skiping this test because it is a webui only endpoint
func TestGetEnvironmentRole(t *testing.T) {
chef := testConnectionWrapper(t)
config := testConfig()
println("Looking for role: ", config.RequiredRole.Name)
println("In", config.RequiredEnvironment.Name)
test, ok, err := chef.GetEnvironmentRole(config.RequiredEnvironment.Name, config.RequiredRole.Name)
if err != nil {
t.Error(err)
}
if !ok {
t.Error("Couldn't find required role in required environment")
}
t.Log(test)
}