diff --git a/pkg/middleware/jwt_middleware_test.go b/pkg/middleware/jwt_middleware_test.go index 780d3aa3..2a98180f 100644 --- a/pkg/middleware/jwt_middleware_test.go +++ b/pkg/middleware/jwt_middleware_test.go @@ -14,7 +14,7 @@ import ( "github.com/codeready-toolchain/registration-service/pkg/proxy" "github.com/codeready-toolchain/registration-service/pkg/server" "github.com/codeready-toolchain/registration-service/test" - "github.com/codeready-toolchain/registration-service/test/fake" + "github.com/codeready-toolchain/registration-service/test/util" "github.com/codeready-toolchain/toolchain-common/pkg/status" commontest "github.com/codeready-toolchain/toolchain-common/pkg/test" authsupport "github.com/codeready-toolchain/toolchain-common/pkg/test/auth" @@ -77,7 +77,7 @@ func (s *TestAuthMiddlewareSuite) TestAuthMiddlewareService() { keysEndpointURL := tokengenerator.NewKeyServer().URL // create server - srv := server.New(fake.NewMockableApplication()) + srv := server.New(util.PrepareInClusterApplication(s.T())) // set the key service url in the config s.SetConfig(testconfig.RegistrationService(). diff --git a/pkg/middleware/promhttp_middleware_test.go b/pkg/middleware/promhttp_middleware_test.go index 45c3c4e8..a1769b45 100644 --- a/pkg/middleware/promhttp_middleware_test.go +++ b/pkg/middleware/promhttp_middleware_test.go @@ -11,7 +11,7 @@ import ( "github.com/codeready-toolchain/registration-service/pkg/proxy" "github.com/codeready-toolchain/registration-service/pkg/server" "github.com/codeready-toolchain/registration-service/test" - "github.com/codeready-toolchain/registration-service/test/fake" + "github.com/codeready-toolchain/registration-service/test/util" commontest "github.com/codeready-toolchain/toolchain-common/pkg/test" authsupport "github.com/codeready-toolchain/toolchain-common/pkg/test/auth" testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config" @@ -35,7 +35,7 @@ func TestPromHTTPMiddlewareSuite(t *testing.T) { func (s *PromHTTPMiddlewareSuite) TestPromHTTPMiddleware() { // given tokengenerator := authsupport.NewTokenManager() - srv := server.New(fake.NewMockableApplication()) + srv := server.New(util.PrepareInClusterApplication(s.T())) keysEndpointURL := tokengenerator.NewKeyServer().URL s.SetConfig(testconfig.RegistrationService(). Environment(configuration.UnitTestsEnvironment). diff --git a/pkg/proxy/proxy_community_test.go b/pkg/proxy/proxy_community_test.go index aeaf32fa..793bccfd 100644 --- a/pkg/proxy/proxy_community_test.go +++ b/pkg/proxy/proxy_community_test.go @@ -148,8 +148,6 @@ func (s *TestProxySuite) checkProxyCommunityOK(fakeApp *fake.ProxyFakeApp, p *Pr fakeApp.MemberClusterServiceMock = s.newMemberClusterServiceWithMembers(p.Client, signupService, testServer.URL) fakeApp.SignupServiceMock = signupService - s.Application.MockSignupService(signupService) - // configure proxy p.spaceLister = &handlers.SpaceLister{ Client: p.Client, diff --git a/pkg/proxy/proxy_test.go b/pkg/proxy/proxy_test.go index 8d87df7d..44460e11 100644 --- a/pkg/proxy/proxy_test.go +++ b/pkg/proxy/proxy_test.go @@ -840,7 +840,6 @@ func (s *TestProxySuite) checkProxyOK(fakeApp *fake.ProxyFakeApp, p *Proxy) { }, }), ) - s.Application.MockSignupService(fakeApp.SignupServiceMock) proxyPlugin := &toolchainv1alpha1.ProxyPlugin{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/proxy/service/cluster_service_test.go b/pkg/proxy/service/cluster_service_test.go index 4e05e5d0..7a04ac77 100644 --- a/pkg/proxy/service/cluster_service_test.go +++ b/pkg/proxy/service/cluster_service_test.go @@ -68,7 +68,6 @@ func (s *TestClusterServiceSuite) TestGetClusterAccess() { Ready: true, }, })) - s.Application.MockSignupService(sc) pp := &toolchainv1alpha1.ProxyPlugin{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index fc37e81c..4f678c73 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -10,6 +10,7 @@ import ( "github.com/codeready-toolchain/registration-service/pkg/server" "github.com/codeready-toolchain/registration-service/test" "github.com/codeready-toolchain/registration-service/test/fake" + "github.com/codeready-toolchain/registration-service/test/util" commontest "github.com/codeready-toolchain/toolchain-common/pkg/test" "github.com/prometheus/client_golang/prometheus" @@ -36,7 +37,7 @@ const ( func (s *TestServerSuite) TestServer() { // We're using the example config for the configuration here as the // specific config params do not matter for testing the routes setup. - srv := server.New(fake.NewMockableApplication()) + srv := server.New(util.PrepareInClusterApplication(s.T())) fake.MockKeycloakCertsCall(s.T()) // Setting up the routes. diff --git a/test/fake/mockable_application.go b/test/fake/mockable_application.go deleted file mode 100644 index c3416b94..00000000 --- a/test/fake/mockable_application.go +++ /dev/null @@ -1,40 +0,0 @@ -package fake - -import ( - "github.com/codeready-toolchain/registration-service/pkg/application/service" - "github.com/codeready-toolchain/registration-service/pkg/application/service/factory" -) - -func NewMockableApplication(options ...factory.Option) *MockableApplication { - return &MockableApplication{ - serviceFactory: factory.NewServiceFactory(options...), - } -} - -type MockableApplication struct { - serviceFactory *factory.ServiceFactory - mockSignupService service.SignupService - mockVerificationService service.VerificationService -} - -func (m *MockableApplication) SignupService() service.SignupService { - if m.mockSignupService != nil { - return m.mockSignupService - } - return m.serviceFactory.SignupService() -} - -func (m *MockableApplication) MockSignupService(svc service.SignupService) { - m.mockSignupService = svc -} - -func (m *MockableApplication) VerificationService() service.VerificationService { - if m.mockVerificationService != nil { - return m.mockVerificationService - } - return m.serviceFactory.VerificationService() -} - -func (m *MockableApplication) MemberClusterService() service.MemberClusterService { - return m.serviceFactory.MemberClusterService() -} diff --git a/test/testsuite.go b/test/testsuite.go index 30d85691..a1bbee07 100644 --- a/test/testsuite.go +++ b/test/testsuite.go @@ -4,10 +4,8 @@ import ( "context" toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" - "github.com/codeready-toolchain/registration-service/pkg/application/service/factory" "github.com/codeready-toolchain/registration-service/pkg/configuration" "github.com/codeready-toolchain/registration-service/pkg/log" - "github.com/codeready-toolchain/registration-service/test/fake" commonconfig "github.com/codeready-toolchain/toolchain-common/pkg/configuration" "github.com/codeready-toolchain/toolchain-common/pkg/test" testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config" @@ -23,9 +21,7 @@ import ( // UnitTestSuite is the base test suite for unit tests. type UnitTestSuite struct { suite.Suite - Application *fake.MockableApplication - ConfigClient *test.FakeClient - factoryOptions []factory.Option + ConfigClient *test.FakeClient } // SetupSuite sets the suite up and sets testmode. @@ -36,19 +32,16 @@ func (s *UnitTestSuite) SetupSuite() { } func (s *UnitTestSuite) SetupTest() { - s.factoryOptions = nil s.SetupDefaultApplication() } func (s *UnitTestSuite) SetupDefaultApplication() { // initialize the toolchainconfig cache s.DefaultConfig() - s.Application = fake.NewMockableApplication(s.factoryOptions...) } func (s *UnitTestSuite) OverrideApplicationDefault(opts ...testconfig.ToolchainConfigOption) { s.SetConfig(opts...) - s.Application = fake.NewMockableApplication(s.factoryOptions...) } func (s *UnitTestSuite) SetConfig(opts ...testconfig.ToolchainConfigOption) configuration.RegistrationServiceConfig { @@ -105,5 +98,4 @@ func (s *UnitTestSuite) DefaultConfig() configuration.RegistrationServiceConfig func (s *UnitTestSuite) TearDownSuite() { // summon the GC! commonconfig.ResetCache() - s.Application = nil } diff --git a/test/util/application.go b/test/util/application.go index 0943eb77..cd90c2f7 100644 --- a/test/util/application.go +++ b/test/util/application.go @@ -11,6 +11,11 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) +func PrepareInClusterApplication(t *testing.T, objects ...runtime.Object) application.Application { + _, app := PrepareInClusterApp(t, objects...) + return app +} + func PrepareInClusterApp(t *testing.T, objects ...runtime.Object) (*commontest.FakeClient, application.Application) { return PrepareInClusterAppWithOption(t, func(_ *factory.ServiceFactory) { }, objects...)