diff --git a/pkg/controller/clusterissuers/BUILD.bazel b/pkg/controller/clusterissuers/BUILD.bazel index f1aa6f344..14d00ce63 100644 --- a/pkg/controller/clusterissuers/BUILD.bazel +++ b/pkg/controller/clusterissuers/BUILD.bazel @@ -33,15 +33,11 @@ go_library( go_test( name = "go_default_test", - srcs = [ - "sync_test.go", - "util_test.go", - ], + srcs = ["sync_test.go"], embed = [":go_default_library"], deps = [ "//pkg/apis/certmanager/v1alpha1:go_default_library", "//pkg/controller/test:go_default_library", - "//test/util/generate:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/client-go/testing:go_default_library", diff --git a/pkg/controller/clusterissuers/sync_test.go b/pkg/controller/clusterissuers/sync_test.go index 9d888fb48..752f1b851 100644 --- a/pkg/controller/clusterissuers/sync_test.go +++ b/pkg/controller/clusterissuers/sync_test.go @@ -26,6 +26,7 @@ import ( clientgotesting "k8s.io/client-go/testing" "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1" + testpkg "github.com/jetstack/cert-manager/pkg/controller/test" ) func newFakeIssuerWithStatus(name string, status v1alpha1.IssuerStatus) *v1alpha1.ClusterIssuer { @@ -42,12 +43,17 @@ func TestSync(t *testing.T) { } func TestUpdateIssuerStatus(t *testing.T) { - f := &controllerFixture{} - f.Setup(t) - defer f.Finish(t) + b := &testpkg.Builder{ + T: t, + } + b.Start() + defer b.Stop() - c := f.Controller - fakeClient := f.Builder.FakeCMClient() + c := &controller{} + c.Register(b.Context) + b.Sync() + + fakeClient := b.FakeCMClient() assertNumberOfActions(t, fatalf, filter(fakeClient.Actions()), 0) originalIssuer := newFakeIssuerWithStatus("test", v1alpha1.IssuerStatus{}) diff --git a/pkg/controller/clusterissuers/util_test.go b/pkg/controller/clusterissuers/util_test.go deleted file mode 100644 index 79c84ced7..000000000 --- a/pkg/controller/clusterissuers/util_test.go +++ /dev/null @@ -1,91 +0,0 @@ -/* -Copyright 2019 The Jetstack cert-manager contributors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package clusterissuers - -import ( - "testing" - - "github.com/jetstack/cert-manager/test/util/generate" - - "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1" - "github.com/jetstack/cert-manager/pkg/controller/test" -) - -type controllerFixture struct { - // The Solver under test - Controller *controller - Builder *test.Builder - - // Issuer to be passed to functions on the Solver (a default will be used if nil) - Issuer *v1alpha1.ClusterIssuer - - // PreFn will run before the test is run, but after the fixture has been initialised. - // This is useful if you want to load the clientset with some resources *after* the - // fixture has been created. - PreFn func(*testing.T, *controllerFixture) - // CheckFn should performs checks to ensure the output of the test is as expected. - // Optional additional values may be provided, which represent the output of the - // function under test. - CheckFn func(*testing.T, *controllerFixture, ...interface{}) - // Err should be true if an error is expected from the function under test - Err bool - - // testResources is used to store references to resources used or created during - // the test. - testResources map[string]interface{} -} - -const ( - defaultTestIssuerName = "issuer" - defaultTestNamespace = "default" -) - -func (s *controllerFixture) Setup(t *testing.T) { - if s.Issuer == nil { - s.Issuer = generate.ClusterIssuer(generate.ClusterIssuerConfig{ - Name: defaultTestIssuerName, - Namespace: defaultTestNamespace, - }) - } - if s.testResources == nil { - s.testResources = map[string]interface{}{} - } - if s.Builder == nil { - s.Builder = &test.Builder{} - } - if s.Builder.T == nil { - s.Builder.T = t - } - s.Builder.Start() - s.Controller = &controller{} - s.Controller.Register(s.Builder.Context) - s.Builder.Sync() - if s.PreFn != nil { - s.PreFn(t, s) - s.Builder.Sync() - } -} - -func (s *controllerFixture) Finish(t *testing.T, args ...interface{}) { - defer s.Builder.Stop() - // resync listers before running checks - s.Builder.Sync() - // run custom checks - if s.CheckFn != nil { - s.CheckFn(t, s, args...) - } -} diff --git a/pkg/controller/issuers/BUILD.bazel b/pkg/controller/issuers/BUILD.bazel index 0abba5c0d..f7d369ceb 100644 --- a/pkg/controller/issuers/BUILD.bazel +++ b/pkg/controller/issuers/BUILD.bazel @@ -33,15 +33,11 @@ go_library( go_test( name = "go_default_test", - srcs = [ - "sync_test.go", - "util_test.go", - ], + srcs = ["sync_test.go"], embed = [":go_default_library"], deps = [ "//pkg/apis/certmanager/v1alpha1:go_default_library", "//pkg/controller/test:go_default_library", - "//test/util/generate:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/client-go/testing:go_default_library", diff --git a/pkg/controller/issuers/sync_test.go b/pkg/controller/issuers/sync_test.go index e8851c4e8..36dbe0a32 100644 --- a/pkg/controller/issuers/sync_test.go +++ b/pkg/controller/issuers/sync_test.go @@ -26,6 +26,7 @@ import ( clientgotesting "k8s.io/client-go/testing" "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1" + testpkg "github.com/jetstack/cert-manager/pkg/controller/test" ) func newFakeIssuerWithStatus(name string, status v1alpha1.IssuerStatus) *v1alpha1.Issuer { @@ -42,12 +43,17 @@ func TestSync(t *testing.T) { } func TestUpdateIssuerStatus(t *testing.T) { - f := &controllerFixture{} - f.Setup(t) - defer f.Finish(t) + b := &testpkg.Builder{ + T: t, + } + b.Start() + defer b.Stop() - cmClient := f.Builder.FakeCMClient() - c := f.Controller + c := &controller{} + c.Register(b.Context) + b.Sync() + + cmClient := b.FakeCMClient() assertNumberOfActions(t, fatalf, filter(cmClient.Actions()), 0) originalIssuer := newFakeIssuerWithStatus("test", v1alpha1.IssuerStatus{}) diff --git a/pkg/controller/issuers/util_test.go b/pkg/controller/issuers/util_test.go deleted file mode 100644 index 1c415ff4e..000000000 --- a/pkg/controller/issuers/util_test.go +++ /dev/null @@ -1,91 +0,0 @@ -/* -Copyright 2019 The Jetstack cert-manager contributors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package issuers - -import ( - "testing" - - "github.com/jetstack/cert-manager/test/util/generate" - - "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1" - "github.com/jetstack/cert-manager/pkg/controller/test" -) - -type controllerFixture struct { - // The Solver under test - Controller *controller - Builder *test.Builder - - // Issuer to be passed to functions on the Solver (a default will be used if nil) - Issuer *v1alpha1.Issuer - - // PreFn will run before the test is run, but after the fixture has been initialised. - // This is useful if you want to load the clientset with some resources *after* the - // fixture has been created. - PreFn func(*testing.T, *controllerFixture) - // CheckFn should performs checks to ensure the output of the test is as expected. - // Optional additional values may be provided, which represent the output of the - // function under test. - CheckFn func(*testing.T, *controllerFixture, ...interface{}) - // Err should be true if an error is expected from the function under test - Err bool - - // testResources is used to store references to resources used or created during - // the test. - testResources map[string]interface{} -} - -const ( - defaultTestIssuerName = "issuer" - defaultTestNamespace = "default" -) - -func (s *controllerFixture) Setup(t *testing.T) { - if s.Issuer == nil { - s.Issuer = generate.Issuer(generate.IssuerConfig{ - Name: defaultTestIssuerName, - Namespace: defaultTestNamespace, - }) - } - if s.testResources == nil { - s.testResources = map[string]interface{}{} - } - if s.Builder == nil { - s.Builder = &test.Builder{} - } - if s.Builder.T == nil { - s.Builder.T = t - } - s.Builder.Start() - s.Controller = &controller{} - s.Controller.Register(s.Builder.Context) - s.Builder.Sync() - if s.PreFn != nil { - s.PreFn(t, s) - s.Builder.Sync() - } -} - -func (s *controllerFixture) Finish(t *testing.T, args ...interface{}) { - defer s.Builder.Stop() - // resync listers before running checks - s.Builder.Sync() - // run custom checks - if s.CheckFn != nil { - s.CheckFn(t, s, args...) - } -}