From bf04dc0b2ff07048fed7a5aaaab0cb0b6dc238fb Mon Sep 17 00:00:00 2001 From: Alejandro Visiedo Date: Thu, 8 Aug 2024 22:59:14 +0200 Subject: [PATCH] test: integrate pendo client Signed-off-by: Alejandro Visiedo --- internal/handler/impl/application_test.go | 8 ++++---- internal/infrastructure/router/public_test.go | 13 ++++++++++--- internal/infrastructure/router/router_test.go | 10 ++++++++-- internal/test/smoke/suite_base_test.go | 4 +++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/internal/handler/impl/application_test.go b/internal/handler/impl/application_test.go index 491bd148..e6fa0af8 100644 --- a/internal/handler/impl/application_test.go +++ b/internal/handler/impl/application_test.go @@ -20,14 +20,14 @@ func TestNewHandler(t *testing.T) { require.NotNil(t, sqlMock) require.NotNil(t, gormDB) assert.Panics(t, func() { - NewHandler(nil, nil, nil, nil, nil) + NewHandler(nil, nil, nil, nil, nil, nil) }) assert.Panics(t, func() { - NewHandler(&config.Config{}, nil, nil, nil, nil) + NewHandler(&config.Config{}, nil, nil, nil, nil, nil) }) cfg := test.GetTestConfig() assert.NotPanics(t, func() { - NewHandler(cfg, gormDB, &metrics.Metrics{}, inventoryMock, nil) + NewHandler(cfg, gormDB, &metrics.Metrics{}, inventoryMock, nil, nil) }) } @@ -37,7 +37,7 @@ func TestAppSecrets(t *testing.T) { require.NoError(t, err) cfg := test.GetTestConfig() - handler := NewHandler(cfg, gormDB, &metrics.Metrics{}, inventoryMock, nil) + handler := NewHandler(cfg, gormDB, &metrics.Metrics{}, inventoryMock, nil, nil) app := handler.(*application) assert.NotEmpty(t, app.config.Secrets.DomainRegKey) diff --git a/internal/infrastructure/router/public_test.go b/internal/infrastructure/router/public_test.go index 8d022f9c..707a9c81 100644 --- a/internal/infrastructure/router/public_test.go +++ b/internal/infrastructure/router/public_test.go @@ -18,6 +18,7 @@ import ( "github.com/podengo-project/idmsvc-backend/internal/metrics" "github.com/podengo-project/idmsvc-backend/internal/test" client_inventory "github.com/podengo-project/idmsvc-backend/internal/test/mock/interface/client/inventory" + client_pendo "github.com/podengo-project/idmsvc-backend/internal/usecase/client/pendo" client_rbac "github.com/podengo-project/idmsvc-backend/internal/usecase/client/rbac" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" @@ -43,7 +44,8 @@ func initRbacWrapper(t *testing.T, cfg *config.Config) rbac.Rbac { ctx, cancel := context.WithCancel(context.Background()) defer cancel() svcRbac, mockRbac := mock_rbac.NewRbacMock(ctx, cfg) - svcRbac.Start() + err := svcRbac.Start() + require.NoError(t, err) defer svcRbac.Stop() mockRbac.WaitAddress(3 * time.Second) mockRbac.SetPermissions(mock_rbac.Profiles["domain-admin-profile"]) @@ -77,11 +79,13 @@ func TestNewGroupPublicPanics(t *testing.T) { require.NotNil(t, db) rbac := initRbacWrapper(t, cfg) require.NotNil(t, rbac) + pendo := client_pendo.NewClient(cfg) + require.NotNil(t, pendo) // FIXME Refactor and encapsulate routerConfig in a factory function routerConfig := RouterConfig{ PublicPath: appPrefix + appName, - Handlers: impl.NewHandler(cfg, db, metrics, inventory, rbac), + Handlers: impl.NewHandler(cfg, db, metrics, inventory, rbac, pendo), Metrics: metrics, } routerWrongConfig := RouterConfig{ @@ -175,11 +179,14 @@ func TestNewGroupPublic(t *testing.T) { rbac := initRbacWrapper(t, cfg) require.NotNil(t, rbac) + pendo := client_pendo.NewClient(cfg) + require.NotNil(t, pendo) + // FIXME Refactor and encapsulate routerConfig in a factory function routerConfig := RouterConfig{ PublicPath: appPrefix + appName, Version: "1.0", - Handlers: impl.NewHandler(cfg, db, metrics, inventory, rbac), + Handlers: impl.NewHandler(cfg, db, metrics, inventory, rbac, pendo), Metrics: metrics, } diff --git a/internal/infrastructure/router/router_test.go b/internal/infrastructure/router/router_test.go index d8d64a89..be887da2 100644 --- a/internal/infrastructure/router/router_test.go +++ b/internal/infrastructure/router/router_test.go @@ -14,6 +14,7 @@ import ( "github.com/podengo-project/idmsvc-backend/internal/metrics" "github.com/podengo-project/idmsvc-backend/internal/test" client_inventory "github.com/podengo-project/idmsvc-backend/internal/test/mock/interface/client/inventory" + client_pendo "github.com/podengo-project/idmsvc-backend/internal/usecase/client/pendo" client_rbac "github.com/podengo-project/idmsvc-backend/internal/usecase/client/rbac" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" @@ -186,8 +187,12 @@ func TestNewRouterWithConfig(t *testing.T) { panic(err) } rbac := client_rbac.New(cfg.Clients.RbacBaseURL, rbacClient) + require.NotNil(t, rbac) + pendo := client_pendo.NewClient(cfg) + require.NotNil(t, pendo) + // Create application handlers - app := handler_impl.NewHandler(cfg, db, metrics, inventory, rbac) + app := handler_impl.NewHandler(cfg, db, metrics, inventory, rbac, pendo) goodConfig := RouterConfig{ Version: "1.0", @@ -236,8 +241,9 @@ func TestNewRouterForMetrics(t *testing.T) { panic(err) } rbac := client_rbac.New(cfg.Clients.RbacBaseURL, rbacClient) + pendo := client_pendo.NewClient(cfg) // Create application handlers - app := handler_impl.NewHandler(cfg, db, metrics, inventory, rbac) + app := handler_impl.NewHandler(cfg, db, metrics, inventory, rbac, pendo) goodConfig := RouterConfig{ Version: "1.0", diff --git a/internal/test/smoke/suite_base_test.go b/internal/test/smoke/suite_base_test.go index be050cef..a672e2d5 100644 --- a/internal/test/smoke/suite_base_test.go +++ b/internal/test/smoke/suite_base_test.go @@ -34,6 +34,7 @@ import ( "gorm.io/gorm" service_impl "github.com/podengo-project/idmsvc-backend/internal/infrastructure/service/impl" + client_pendo "github.com/podengo-project/idmsvc-backend/internal/usecase/client/pendo" client_rbac "github.com/podengo-project/idmsvc-backend/internal/usecase/client/rbac" ) @@ -134,7 +135,8 @@ func (s *SuiteBase) SetupTest() { panic(err) } rbac := client_rbac.New(s.cfg.Clients.RbacBaseURL, rbacClient) - s.svc = service_impl.NewApplication(ctx, s.wg, s.cfg, s.db, inventory, rbac) + pendo := client_pendo.NewClient(s.cfg) + s.svc = service_impl.NewApplication(ctx, s.wg, s.cfg, s.db, inventory, rbac, pendo) go func() { if e := s.svc.Start(); e != nil { panic(e)