mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-06-04 11:25:52 +08:00

* fix: support multitenancy in org * fix: register and login working now * fix: changes to migration * fix: migrations run both on sqlite and postgres * fix: remove user flags from fe and be * fix: remove ingestion keys from update * fix: multitenancy support for apdex settings * fix: render ts for users correctly * fix: fix migration to run for new tenants * fix: clean up migrations * fix: address comments * Update pkg/sqlmigration/013_update_organization.go Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix: fix build * fix: force invites with org id * Update pkg/query-service/auth/auth.go Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix: address comments * fix: address comments * fix: provier with their own dialect * fix: update dialects * fix: remove unwanted change * Update pkg/query-service/app/http_handler.go Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix: different files for types --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package utils
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
"go.signoz.io/signoz/pkg/factory"
|
|
"go.signoz.io/signoz/pkg/factory/factorytest"
|
|
"go.signoz.io/signoz/pkg/query-service/app/dashboards"
|
|
"go.signoz.io/signoz/pkg/query-service/dao"
|
|
"go.signoz.io/signoz/pkg/sqlmigration"
|
|
"go.signoz.io/signoz/pkg/sqlmigrator"
|
|
"go.signoz.io/signoz/pkg/sqlstore"
|
|
"go.signoz.io/signoz/pkg/sqlstore/sqlitesqlstore"
|
|
)
|
|
|
|
func NewTestSqliteDB(t *testing.T) (sqlStore sqlstore.SQLStore, testDBFilePath string) {
|
|
testDBFile, err := os.CreateTemp("", "test-signoz-db-*")
|
|
if err != nil {
|
|
t.Fatalf("could not create temp file for test db: %v", err)
|
|
}
|
|
testDBFilePath = testDBFile.Name()
|
|
t.Cleanup(func() { os.Remove(testDBFilePath) })
|
|
testDBFile.Close()
|
|
|
|
sqlStore, err = sqlitesqlstore.New(context.Background(), factorytest.NewSettings(), sqlstore.Config{Provider: "sqlite", Sqlite: sqlstore.SqliteConfig{Path: testDBFilePath}})
|
|
if err != nil {
|
|
t.Fatalf("could not create test db sqlite store: %v", err)
|
|
}
|
|
|
|
sqlmigrations, err := sqlmigration.New(
|
|
context.Background(),
|
|
factorytest.NewSettings(),
|
|
sqlmigration.Config{},
|
|
factory.MustNewNamedMap(
|
|
sqlmigration.NewAddDataMigrationsFactory(),
|
|
sqlmigration.NewAddOrganizationFactory(),
|
|
sqlmigration.NewAddPreferencesFactory(),
|
|
sqlmigration.NewAddDashboardsFactory(),
|
|
sqlmigration.NewAddSavedViewsFactory(),
|
|
sqlmigration.NewAddAgentsFactory(),
|
|
sqlmigration.NewAddPipelinesFactory(),
|
|
sqlmigration.NewAddIntegrationsFactory(),
|
|
sqlmigration.NewAddLicensesFactory(),
|
|
sqlmigration.NewAddPatsFactory(),
|
|
sqlmigration.NewModifyDatetimeFactory(),
|
|
sqlmigration.NewModifyOrgDomainFactory(),
|
|
sqlmigration.NewUpdateOrganizationFactory(sqlStore),
|
|
),
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("could not create test db sql migrations: %v", err)
|
|
}
|
|
|
|
err = sqlmigrator.New(context.Background(), factorytest.NewSettings(), sqlStore, sqlmigrations, sqlmigrator.Config{}).Migrate(context.Background())
|
|
if err != nil {
|
|
t.Fatalf("could not migrate test db sql migrations: %v", err)
|
|
}
|
|
|
|
return sqlStore, testDBFilePath
|
|
}
|
|
|
|
func NewQueryServiceDBForTests(t *testing.T) sqlstore.SQLStore {
|
|
sqlStore, _ := NewTestSqliteDB(t)
|
|
|
|
err := dao.InitDao(sqlStore)
|
|
if err != nil {
|
|
t.Fatalf("could not initialize dao: %v", err)
|
|
}
|
|
dashboards.InitDB(sqlStore.SQLxDB())
|
|
|
|
return sqlStore
|
|
}
|