Skip to content

:sparkles Add env support for setting ErrorIfCRDPathMissing during testing #511

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

Closed
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
20 changes: 19 additions & 1 deletion pkg/envtest/envtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,28 @@ var _ = Describe("Test", func() {
})

Describe("InstallCRDs", func() {

It("should set ErrorIfCRDPathMissing through env settings", func(done Done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it's unclear to me what this is testing, since it doesn't seem to be testing that the setting gets automatically propogated from Environment to InstallCRDs

Copy link
Author

@connor1989 connor1989 Jul 3, 2019

Choose a reason for hiding this comment

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

Yes, it only validates the new option. This was to keep the other tests unchanged here.
https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/envtest/envtest_test.go#L155

My other thought was to make this change directly in BeforeSuite and update all the tests accordingly.

var _ = BeforeSuite(func(done Done) {
	logf.SetLogger(zap.LoggerTo(GinkgoWriter, true))
	env = &Environment{
++   	    ErrorIfCRDPathMissing: true,
        }
	_, err := env.Start()

Any opposition to this?


testEnv := &Environment{
ErrorIfCRDPathMissing: true,
}

crds, err = InstallCRDs(env.Config, CRDInstallOptions{
Paths: []string{"fake"},
ErrorIfPathMissing: testEnv.ErrorIfCRDPathMissing,
})

Expect(err).To(HaveOccurred())

close(done)
})

It("should install the CRDs into the cluster", func(done Done) {

crds, err = InstallCRDs(env.Config, CRDInstallOptions{
Paths: []string{filepath.Join(".", "testdata")},
Paths: []string{filepath.Join(".", "testdata")},
ErrorIfPathMissing: env.ErrorIfCRDPathMissing,
Copy link
Author

Choose a reason for hiding this comment

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

@DirectXMan12 to your first point, although the change is minimal, I did make use of the new option here

Copy link
Contributor

Choose a reason for hiding this comment

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

right, but it's not plumbed through to any non-test logic, afaict

})
Expect(err).NotTo(HaveOccurred())

Expand Down
5 changes: 5 additions & 0 deletions pkg/envtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ type Environment struct {
// loading.
Config *rest.Config

// ErrorIfCRDPathMissing provides an interface for the underlying
// CRDInstallOptions.ErrorIfPathMissing. It prevents silent failures
// for missing CRD paths.
ErrorIfCRDPathMissing bool

// CRDs is a list of CRDs to install
CRDs []*apiextensionsv1beta1.CustomResourceDefinition

Expand Down