Skip to content

Don't fail envtest if directory is missing #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/envtest/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type CRDInstallOptions struct {
// CRDs is a list of CRDs to install
CRDs []*apiextensionsv1beta1.CustomResourceDefinition

// ErrorIfPathMissing will cause an error if a Path does not exist
ErrorIfPathMissing bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sensible default in this case would be true, but its the opposite currently. Consider renaming it something like SkipMissingCRDs ? so that default is *to error if files missing".

Which case do you need this ?

Copy link
Contributor Author

@pwittrock pwittrock Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary for scaffolded projects without custom resources. I ran into this when creating a new controller-only project for deployments. The scaffolded test tried to read the crds, but the directory didn't exist because there were no user defined resources.

We probably want to scaffold this to default to not-error so that the projects work without custom resources, but pick them up if they are added later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good.


// maxTime is the max time to wait
maxTime time.Duration

Expand Down Expand Up @@ -75,6 +78,9 @@ func InstallCRDs(config *rest.Config, options CRDInstallOptions) ([]*apiextensio
func readCRDFiles(options *CRDInstallOptions) error {
if len(options.Paths) > 0 {
for _, path := range options.Paths {
if _, err := os.Stat(path); !options.ErrorIfPathMissing && os.IsNotExist(err) {
continue
}
new, err := readCRDs(path)
if err != nil {
return err
Expand Down
9 changes: 8 additions & 1 deletion pkg/envtest/envtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ var _ = Describe("Test", func() {
close(done)
}, 5)

It("should return an error if the directory doesn't exist", func(done Done) {
It("should not return an not error if the directory doesn't exist", func(done Done) {
crds, err = InstallCRDs(env.Config, CRDInstallOptions{Paths: []string{"fake"}})
Expect(err).NotTo(HaveOccurred())

close(done)
}, 5)

It("should return an error if the directory doesn't exist", func(done Done) {
crds, err = InstallCRDs(env.Config, CRDInstallOptions{Paths: []string{"fake"}, ErrorIfPathMissing: true})
Expect(err).To(HaveOccurred())

close(done)
Expand Down