-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathantifreeze_test.go
184 lines (156 loc) · 5.31 KB
/
antifreeze_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package main_test
import (
"testing"
"code.cloudfoundry.org/cli/plugin/models"
"code.cloudfoundry.org/cli/plugin/pluginfakes"
. "github.com/odlp/antifreeze"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestAntifreeze(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Antifreeze Suite")
}
var _ = Describe("Flag Parsing", func() {
It("parses args", func() {
appName, manifestPath, err := ParseArgs(
[]string{
"validate-manifest-ok",
"app-name",
"-f", "manifest-path",
},
)
Expect(err).ToNot(HaveOccurred())
Expect(appName).To(Equal("app-name"))
Expect(manifestPath).To(Equal("manifest-path"))
})
It("requires a manifest", func() {
_, _, err := ParseArgs(
[]string{
"validate-manifest-ok",
"app-name",
},
)
Expect(err).To(MatchError("Missing manifest argument"))
})
})
var _ = Describe("Parsing Manifest", func() {
It("parses the ENV keys", func() {
envKeys, _, err := ParseManifest("./fixtures/manifest.yml", "app-name")
Expect(err).ToNot(HaveOccurred())
Expect(envKeys).To(HaveLen(2))
Expect(envKeys).To(ContainElement("ENV_VAR_1"))
Expect(envKeys).To(ContainElement("ENV_VAR_2"))
})
It("parses the service names", func() {
_, serviceNames, err := ParseManifest("./fixtures/manifest.yml", "app-name")
Expect(err).ToNot(HaveOccurred())
Expect(serviceNames).To(HaveLen(2))
Expect(serviceNames).To(ContainElement("service-1"))
Expect(serviceNames).To(ContainElement("service-2"))
})
Context("multi-app manifest", func() {
It("returns the values for the correct app", func() {
envKeys, serviceNames, err := ParseManifest("./fixtures/multi-manifest.yml", "app-2")
Expect(err).ToNot(HaveOccurred())
Expect(serviceNames).To(HaveLen(2))
Expect(serviceNames).To(ContainElement("service-3"))
Expect(serviceNames).To(ContainElement("service-4"))
Expect(envKeys).To(HaveLen(2))
Expect(envKeys).To(ContainElement("ENV_VAR_3"))
Expect(envKeys).To(ContainElement("ENV_VAR_4"))
})
})
Context("app doesn't exist in the manifest", func() {
It("returns an error", func() {
_, _, err := ParseManifest("./fixtures/multi-manifest.yml", "app-666")
Expect(err).To(MatchError("Application 'app-666' not found in manifest"))
})
})
Context("invalid manifest path", func() {
It("returns an error", func() {
_, _, err := ParseManifest("./pure-fiction", "fictional-app")
Expect(err).To(MatchError("Unable to read manifest file: ./pure-fiction"))
})
})
Context("invalid manifest", func() {
It("returns an error", func() {
_, _, err := ParseManifest("./fixtures/invalid-manifest.json", "app-name")
Expect(err).To(MatchError("No application found in manifest"))
})
})
})
var _ = Describe("Get App Env And Services", func() {
var cliConnection *pluginfakes.FakeCliConnection
var fakeApp plugin_models.GetAppModel
BeforeEach(func() {
cliConnection = &pluginfakes.FakeCliConnection{}
fakeAppEnv := map[string]interface{}{"ENV_VAR_1": "foo", "ENV_VAR_2": "bar"}
service1 := plugin_models.GetApp_ServiceSummary{
Name: "service-1",
}
service2 := plugin_models.GetApp_ServiceSummary{
Name: "service-2",
}
fakeApp = plugin_models.GetAppModel{
EnvironmentVars: fakeAppEnv,
Services: []plugin_models.GetApp_ServiceSummary{service1, service2},
}
cliConnection.GetAppStub = func(arg1 string) (plugin_models.GetAppModel, error) {
Expect(arg1).To(Equal("app-name"))
return fakeApp, nil
}
})
It("returns the ENV keys from the application", func() {
appEnv, _, err := GetAppEnvAndServices(cliConnection, "app-name")
Expect(err).ToNot(HaveOccurred())
Expect(appEnv).To(HaveLen(2))
Expect(appEnv).To(ContainElement("ENV_VAR_1"))
Expect(appEnv).To(ContainElement("ENV_VAR_2"))
})
It("returns the service keys from the application", func() {
_, appServices, err := GetAppEnvAndServices(cliConnection, "app-name")
Expect(err).ToNot(HaveOccurred())
Expect(appServices).To(HaveLen(2))
Expect(appServices).To(ContainElement("service-1"))
Expect(appServices).To(ContainElement("service-2"))
})
})
var _ = Describe("Missing From Manifest", func() {
Context("no differences", func() {
It("returns an empty slice", func() {
manifestEnv := []string{"ENV_VAR_1"}
appEnv := []string{"ENV_VAR_1"}
difference := MissingFromManifest(manifestEnv, appEnv)
Expect(difference).To(HaveLen(0))
})
})
Context("manifest has additional values", func() {
It("returns an empty slice", func() {
manifestEnv := []string{"ENV_VAR_1", "ENV_VAR_2"}
appEnv := []string{"ENV_VAR_1"}
difference := MissingFromManifest(manifestEnv, appEnv)
Expect(difference).To(HaveLen(0))
})
})
Context("app has additional values", func() {
It("returns the offending values", func() {
manifestEnv := []string{"ENV_VAR_1"}
appEnv := []string{"ENV_VAR_1", "ENV_SNOW", "ENV_FLAKE"}
difference := MissingFromManifest(manifestEnv, appEnv)
Expect(difference).To(HaveLen(2))
Expect(difference).To(ContainElement("ENV_SNOW"))
Expect(difference).To(ContainElement("ENV_FLAKE"))
})
})
})
var _ = Describe("GetMetadata", func() {
It("returns valid metadata", func() {
plugin := AntifreezePlugin{}
metadata := plugin.GetMetadata()
Expect(metadata.Name).To(Equal("antifreeze"))
Expect(metadata.Version).ToNot(BeNil())
Expect(metadata.MinCliVersion).ToNot(BeNil())
Expect(metadata.Commands).To(HaveLen(1))
})
})