diff --git a/controllers/common_test.go b/controllers/common_test.go new file mode 100644 index 00000000..bc8ed016 --- /dev/null +++ b/controllers/common_test.go @@ -0,0 +1,30 @@ +package controllers_test + +import ( + "testing" + + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/fake" + + billingv1 "github.com/appuio/control-api/apis/billing/v1" + orgv1 "github.com/appuio/control-api/apis/organization/v1" + userv1 "github.com/appuio/control-api/apis/user/v1" + controlv1 "github.com/appuio/control-api/apis/v1" +) + +func prepareTest(t *testing.T, initObjs ...client.Object) client.WithWatch { + scheme := runtime.NewScheme() + utilruntime.Must(clientgoscheme.AddToScheme(scheme)) + utilruntime.Must(orgv1.AddToScheme(scheme)) + utilruntime.Must(controlv1.AddToScheme(scheme)) + utilruntime.Must(billingv1.AddToScheme(scheme)) + utilruntime.Must(userv1.AddToScheme(scheme)) + + return fake.NewClientBuilder(). + WithScheme(scheme). + WithObjects(initObjs...). + Build() +} diff --git a/controllers/user_controller_test.go b/controllers/user_controller_test.go index 4326d4ca..9bf78b80 100644 --- a/controllers/user_controller_test.go +++ b/controllers/user_controller_test.go @@ -8,18 +8,10 @@ import ( "github.com/stretchr/testify/require" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - clientgoscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/record" ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/fake" - billingv1 "github.com/appuio/control-api/apis/billing/v1" - orgv1 "github.com/appuio/control-api/apis/organization/v1" - userv1 "github.com/appuio/control-api/apis/user/v1" controlv1 "github.com/appuio/control-api/apis/v1" . "github.com/appuio/control-api/controllers" ) @@ -67,17 +59,3 @@ func Test_UserController_Reconcile_Success(t *testing.T) { assert.Len(t, crb.Subjects, 1, "ClusterRoleBinding should have subject referencing the user") assert.Equal(t, userPrefix+subject.Name, crb.Subjects[0].Name, "user name must match and include prefix") } - -func prepareTest(t *testing.T, initObjs ...client.Object) client.WithWatch { - scheme := runtime.NewScheme() - utilruntime.Must(clientgoscheme.AddToScheme(scheme)) - utilruntime.Must(orgv1.AddToScheme(scheme)) - utilruntime.Must(controlv1.AddToScheme(scheme)) - utilruntime.Must(billingv1.AddToScheme(scheme)) - utilruntime.Must(userv1.AddToScheme(scheme)) - - return fake.NewClientBuilder(). - WithScheme(scheme). - WithObjects(initObjs...). - Build() -}