mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 07:47:32 +00:00
feat: add embedded testing server for postgres (#9955)
# Which Problems Are Solved 1. there was no embedded database to run tests against 2. there were no tests for postgres/migrate 3. there was no test setup for repository which starts a client for the embedded database # How the Problems Are Solved 1. postgres/embedded package was added 2. tests were added 3. TestMain was added incl. an example test # Additional Changes none # Additional Context closes #9934 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
16
backend/v3/storage/database/repository/org_test.go
Normal file
16
backend/v3/storage/database/repository/org_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TestBla is an example and can be removed later
|
||||
func TestBla(t *testing.T) {
|
||||
var count int
|
||||
err := pool.QueryRow(context.Background(), "select count(*) from zitadel.instances").Scan(&count)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 0, count)
|
||||
}
|
41
backend/v3/storage/database/repository/repository_test.go
Normal file
41
backend/v3/storage/database/repository/repository_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database/dialect/postgres/embedded"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
os.Exit(runTests(m))
|
||||
}
|
||||
|
||||
var pool database.Pool
|
||||
|
||||
func runTests(m *testing.M) int {
|
||||
connector, stop, err := embedded.StartEmbedded()
|
||||
if err != nil {
|
||||
log.Fatalf("unable to start embedded postgres: %v", err)
|
||||
}
|
||||
defer stop()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
pool, err = connector.Connect(ctx)
|
||||
if err != nil {
|
||||
log.Printf("unable to connect to embedded postgres: %v", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
err = pool.Migrate(ctx)
|
||||
if err != nil {
|
||||
log.Printf("unable to migrate database: %v", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
return m.Run()
|
||||
}
|
Reference in New Issue
Block a user