SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(signoz): compile time check for dependency injection (#8033)
Vibhu Pandey403630ad3165
diff --git a/pkg/emailing/emailingtest/provider.go b/pkg/emailing/emailingtest/provider.gonew file mode 100644index 0000000000..1db2b8d997--- /dev/null+++ b/pkg/emailing/emailingtest/provider.go@@ -0,0 +1,28 @@+package emailingtest++import (+ "context"++ "github.com/SigNoz/signoz/pkg/emailing"+ "github.com/SigNoz/signoz/pkg/types/emailtypes"+)++var _ emailing.Emailing = (*Provider)(nil)++type Provider struct {+ SentEmailCountByTo map[string]int+ SentEmailCountByTemplateName map[emailtypes.TemplateName]int+}++func New() *Provider {+ return &Provider{+ SentEmailCountByTo: make(map[string]int),+ SentEmailCountByTemplateName: make(map[emailtypes.TemplateName]int),+ }+}++func (provider *Provider) SendHTML(ctx context.Context, to string, subject string, templateName emailtypes.TemplateName, data map[string]any) error {+ provider.SentEmailCountByTo[to]+++ provider.SentEmailCountByTemplateName[templateName]+++ return nil+}diff --git a/pkg/signoz/handler_test.go b/pkg/signoz/handler_test.gonew file mode 100644index 0000000000..d28ab38376--- /dev/null+++ b/pkg/signoz/handler_test.go@@ -0,0 +1,36 @@+package signoz++import (+ "reflect"+ "testing"+ "time"++ "github.com/DATA-DOG/go-sqlmock"+ "github.com/SigNoz/signoz/pkg/emailing/emailingtest"+ "github.com/SigNoz/signoz/pkg/factory/factorytest"+ "github.com/SigNoz/signoz/pkg/modules/user/impluser"+ "github.com/SigNoz/signoz/pkg/sqlstore"+ "github.com/SigNoz/signoz/pkg/sqlstore/sqlstoretest"+ "github.com/SigNoz/signoz/pkg/types/authtypes"+ "github.com/stretchr/testify/assert"+)++// This is a test to ensure that all fields of the handlers are initialized.+// It also helps us catch these errors at compile time instead of runtime.+func TestNewHandlers(t *testing.T) {+ sqlstore := sqlstoretest.New(sqlstore.Config{Provider: "sqlite"}, sqlmock.QueryMatcherEqual)+ jwt := authtypes.NewJWT("", 1*time.Hour, 1*time.Hour)+ emailing := emailingtest.New()+ providerSettings := factorytest.NewSettings()+ userModule := impluser.NewModule(impluser.NewStore(sqlstore), jwt, emailing, providerSettings)+ userHandler := impluser.NewHandler(userModule)++ modules := NewModules(sqlstore, userModule)+ handlers := NewHandlers(modules, userHandler)++ reflectVal := reflect.ValueOf(handlers)+ for i := 0; i < reflectVal.NumField(); i++ {+ f := reflectVal.Field(i)+ assert.False(t, f.IsZero(), "%s handler has not been initialized", reflectVal.Type().Field(i).Name)+ }+}diff --git a/pkg/signoz/module_test.go b/pkg/signoz/module_test.gonew file mode 100644index 0000000000..566cb41e0e--- /dev/null+++ b/pkg/signoz/module_test.go@@ -0,0 +1,34 @@+package signoz++import (+ "reflect"+ "testing"+ "time"++ "github.com/DATA-DOG/go-sqlmock"+ "github.com/SigNoz/signoz/pkg/emailing/emailingtest"+ "github.com/SigNoz/signoz/pkg/factory/factorytest"+ "github.com/SigNoz/signoz/pkg/modules/user/impluser"+ "github.com/SigNoz/signoz/pkg/sqlstore"+ "github.com/SigNoz/signoz/pkg/sqlstore/sqlstoretest"+ "github.com/SigNoz/signoz/pkg/types/authtypes"+ "github.com/stretchr/testify/assert"+)++// This is a test to ensure that all fields of the modules are initialized.+// It also helps us catch these errors at compile time instead of runtime.+func TestNewModules(t *testing.T) {+ sqlstore := sqlstoretest.New(sqlstore.Config{Provider: "sqlite"}, sqlmock.QueryMatcherEqual)+ jwt := authtypes.NewJWT("", 1*time.Hour, 1*time.Hour)+ emailing := emailingtest.New()+ providerSettings := factorytest.NewSettings()+ userModule := impluser.NewModule(impluser.NewStore(sqlstore), jwt, emailing, providerSettings)++ modules := NewModules(sqlstore, userModule)++ reflectVal := reflect.ValueOf(modules)+ for i := 0; i < reflectVal.NumField(); i++ {+ f := reflectVal.Field(i)+ assert.False(t, f.IsZero(), "%s module has not been initialized", reflectVal.Type().Field(i).Name)+ }+}