Skip to content

Commit

Permalink
fix migration test. (#396)
Browse files Browse the repository at this point in the history
* fix migration test.

* fix migration test.
  • Loading branch information
sudiptob2 authored Jan 15, 2025
1 parent e863911 commit 1d9a953
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions internal/database/migrations/gomigrate_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package migrations

import (
"context"
"fmt"
"testing"

"github.com/G-Research/unicorn-history-server/internal/log"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand All @@ -14,7 +17,9 @@ import (

type GoMigrateIntTest struct {
suite.Suite
tp *database.TestPostgresContainer
tp *database.TestPostgresContainer
pool *pgxpool.Pool
cfg *database.InstanceConfig
}

func (ts *GoMigrateIntTest) SetupSuite() {
Expand All @@ -30,6 +35,8 @@ func (ts *GoMigrateIntTest) SetupSuite() {
tp, err := database.NewTestPostgresContainer(ctx, cfg)
require.NoError(ts.T(), err)
ts.tp = tp
ts.pool = tp.Pool(ctx, ts.T(), &cfg)
ts.cfg = &cfg
}

func (ts *GoMigrateIntTest) TearDownSuite() {
Expand All @@ -39,14 +46,23 @@ func (ts *GoMigrateIntTest) TearDownSuite() {

func (ts *GoMigrateIntTest) TestGoMigrate() {
ctx := context.Background()

schema := database.CreateTestSchema(ctx, ts.T())
ts.T().Cleanup(func() {
database.DropTestSchema(ctx, ts.T(), schema)
})
log.Init(config.GetTestLogConfig())

cfg := config.GetTestPostgresConfig()
cfg.Schema = schema
cfg.Host = ts.cfg.Host
cfg.Port = ts.cfg.Port
cfg.Username = ts.cfg.User
cfg.Password = ts.cfg.Password
cfg.DbName = ts.cfg.DBName
cfg.Schema = "test"

_, err := ts.pool.Exec(ctx, fmt.Sprintf("CREATE SCHEMA %s", cfg.Schema))
require.NoError(ts.T(), err)

setSearchPathQuery := fmt.Sprintf("SET search_path TO %s", cfg.Schema)
_, err = ts.pool.Exec(ctx, setSearchPathQuery)
require.NoError(ts.T(), err)

m, err := New(cfg, "../../../migrations")
require.NoError(ts.T(), err)

Expand Down

0 comments on commit 1d9a953

Please sign in to comment.