Skip to content

Commit 08de469

Browse files
committed
Adding tests for multiple directory and file usage
1 parent 40f3736 commit 08de469

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

pkg/envtest/crd.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ func renderCRDs(options *CRDInstallOptions) ([]*apiextensionsv1beta1.CustomResou
257257
}
258258

259259
log.V(1).Info("reading CRDs from path", "path", path)
260-
261260
crdList, err := readCRDs(filePath, files)
262261
if err != nil {
263262
return nil, err
@@ -267,7 +266,6 @@ func renderCRDs(options *CRDInstallOptions) ([]*apiextensionsv1beta1.CustomResou
267266
if existsCRDs(crds, crdList) {
268267
continue
269268
}
270-
271269
crds = append(crds, crdList...)
272270
}
273271

pkg/envtest/envtest_test.go

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ var _ = Describe("Test", func() {
6969
})
7070

7171
Describe("InstallCRDs", func() {
72-
It("should install the CRDs into the cluster", func(done Done) {
73-
72+
It("should install the CRDs into the cluster using directory", func(done Done) {
7473
crds, err = InstallCRDs(env.Config, CRDInstallOptions{
7574
Paths: []string{filepath.Join(".", "testdata")},
7675
})
@@ -163,6 +162,65 @@ var _ = Describe("Test", func() {
163162
close(done)
164163
}, 5)
165164

165+
It("should install the CRDs into the cluster using file", func(done Done) {
166+
crds, err = InstallCRDs(env.Config, CRDInstallOptions{
167+
Paths: []string{filepath.Join(".", "testdata", "examplecrd2.yaml")},
168+
})
169+
Expect(err).NotTo(HaveOccurred())
170+
171+
crd := &v1beta1.CustomResourceDefinition{}
172+
err = c.Get(context.TODO(), types.NamespacedName{Name: "bazs.qux.example.com"}, crd)
173+
Expect(err).NotTo(HaveOccurred())
174+
Expect(crd.Spec.Names.Kind).To(Equal("Baz"))
175+
176+
err = WaitForCRDs(env.Config, []*v1beta1.CustomResourceDefinition{
177+
{
178+
Spec: v1beta1.CustomResourceDefinitionSpec{
179+
Group: "qux.example.com",
180+
Version: "v1beta1",
181+
Names: v1beta1.CustomResourceDefinitionNames{
182+
Plural: "bazs",
183+
}},
184+
},
185+
},
186+
CRDInstallOptions{MaxTime: 50 * time.Millisecond, PollInterval: 15 * time.Millisecond},
187+
)
188+
Expect(err).NotTo(HaveOccurred())
189+
190+
close(done)
191+
}, 10)
192+
193+
It("should filter out already existent CRD", func(done Done) {
194+
crds, err = InstallCRDs(env.Config, CRDInstallOptions{
195+
Paths: []string{
196+
filepath.Join(".", "testdata"),
197+
filepath.Join(".", "testdata", "examplecrd1.yaml"),
198+
},
199+
})
200+
Expect(err).NotTo(HaveOccurred())
201+
202+
crd := &v1beta1.CustomResourceDefinition{}
203+
err = c.Get(context.TODO(), types.NamespacedName{Name: "foos.bar.example.com"}, crd)
204+
Expect(err).NotTo(HaveOccurred())
205+
Expect(crd.Spec.Names.Kind).To(Equal("Foo"))
206+
207+
err = WaitForCRDs(env.Config, []*v1beta1.CustomResourceDefinition{
208+
{
209+
Spec: v1beta1.CustomResourceDefinitionSpec{
210+
Group: "bar.example.com",
211+
Version: "v1beta1",
212+
Names: v1beta1.CustomResourceDefinitionNames{
213+
Plural: "foos",
214+
}},
215+
},
216+
},
217+
CRDInstallOptions{MaxTime: 50 * time.Millisecond, PollInterval: 15 * time.Millisecond},
218+
)
219+
Expect(err).NotTo(HaveOccurred())
220+
221+
close(done)
222+
}, 10)
223+
166224
It("should not return an not error if the directory doesn't exist", func(done Done) {
167225
crds, err = InstallCRDs(env.Config, CRDInstallOptions{Paths: []string{"fake"}})
168226
Expect(err).NotTo(HaveOccurred())
@@ -177,6 +235,15 @@ var _ = Describe("Test", func() {
177235
close(done)
178236
}, 5)
179237

238+
It("should return an error if the file doesn't exist", func(done Done) {
239+
crds, err = InstallCRDs(env.Config, CRDInstallOptions{Paths: []string{
240+
filepath.Join(".", "testdata", "fake.yaml")}, ErrorIfPathMissing: true,
241+
})
242+
Expect(err).To(HaveOccurred())
243+
244+
close(done)
245+
}, 5)
246+
180247
It("should return an error if the resource group version isn't found", func(done Done) {
181248
// Wait for a CRD where the Group and Version don't exist
182249
err := WaitForCRDs(env.Config,

0 commit comments

Comments
 (0)