Skip to content

Commit

Permalink
drop MockableApplication (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek authored Nov 4, 2024
1 parent 795ca54 commit 738daee
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 58 deletions.
4 changes: 2 additions & 2 deletions pkg/middleware/jwt_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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().
Expand Down
4 changes: 2 additions & 2 deletions pkg/middleware/promhttp_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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).
Expand Down
2 changes: 0 additions & 2 deletions pkg/proxy/proxy_community_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion pkg/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,6 @@ func (s *TestProxySuite) checkProxyOK(fakeApp *fake.ProxyFakeApp, p *Proxy) {
},
}),
)
s.Application.MockSignupService(fakeApp.SignupServiceMock)

proxyPlugin := &toolchainv1alpha1.ProxyPlugin{
ObjectMeta: metav1.ObjectMeta{
Expand Down
1 change: 0 additions & 1 deletion pkg/proxy/service/cluster_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func (s *TestClusterServiceSuite) TestGetClusterAccess() {
Ready: true,
},
}))
s.Application.MockSignupService(sc)

pp := &toolchainv1alpha1.ProxyPlugin{
ObjectMeta: metav1.ObjectMeta{
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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.
Expand Down
40 changes: 0 additions & 40 deletions test/fake/mockable_application.go

This file was deleted.

10 changes: 1 addition & 9 deletions test/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -105,5 +98,4 @@ func (s *UnitTestSuite) DefaultConfig() configuration.RegistrationServiceConfig
func (s *UnitTestSuite) TearDownSuite() {
// summon the GC!
commonconfig.ResetCache()
s.Application = nil
}
5 changes: 5 additions & 0 deletions test/util/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down

0 comments on commit 738daee

Please sign in to comment.