Skip to content

Commit 89e841b

Browse files
authored
Merge pull request #65 from pwittrock/operator
Don't fail envtest if directory is missing
2 parents 2430f9c + edd9073 commit 89e841b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/envtest/crd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type CRDInstallOptions struct {
3939
// CRDs is a list of CRDs to install
4040
CRDs []*apiextensionsv1beta1.CustomResourceDefinition
4141

42+
// ErrorIfPathMissing will cause an error if a Path does not exist
43+
ErrorIfPathMissing bool
44+
4245
// maxTime is the max time to wait
4346
maxTime time.Duration
4447

@@ -75,6 +78,9 @@ func InstallCRDs(config *rest.Config, options CRDInstallOptions) ([]*apiextensio
7578
func readCRDFiles(options *CRDInstallOptions) error {
7679
if len(options.Paths) > 0 {
7780
for _, path := range options.Paths {
81+
if _, err := os.Stat(path); !options.ErrorIfPathMissing && os.IsNotExist(err) {
82+
continue
83+
}
7884
new, err := readCRDs(path)
7985
if err != nil {
8086
return err

pkg/envtest/envtest_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ var _ = Describe("Test", func() {
8484
close(done)
8585
}, 5)
8686

87-
It("should return an error if the directory doesn't exist", func(done Done) {
87+
It("should not return an not error if the directory doesn't exist", func(done Done) {
8888
crds, err = InstallCRDs(env.Config, CRDInstallOptions{Paths: []string{"fake"}})
89+
Expect(err).NotTo(HaveOccurred())
90+
91+
close(done)
92+
}, 5)
93+
94+
It("should return an error if the directory doesn't exist", func(done Done) {
95+
crds, err = InstallCRDs(env.Config, CRDInstallOptions{Paths: []string{"fake"}, ErrorIfPathMissing: true})
8996
Expect(err).To(HaveOccurred())
9097

9198
close(done)

0 commit comments

Comments
 (0)