Skip to content

Commit

Permalink
test: integrate pendo client
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Visiedo <[email protected]>
  • Loading branch information
avisiedo authored and pvoborni committed Aug 15, 2024
1 parent 7f31fe8 commit bf04dc0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
8 changes: 4 additions & 4 deletions internal/handler/impl/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand All @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions internal/infrastructure/router/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"])
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
}

Expand Down
10 changes: 8 additions & 2 deletions internal/infrastructure/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion internal/test/smoke/suite_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bf04dc0

Please sign in to comment.