diff --git a/cmd/local/local.go b/cmd/local/local.go index ffbbdea..f58d9eb 100644 --- a/cmd/local/local.go +++ b/cmd/local/local.go @@ -52,7 +52,7 @@ func local(cfg *LocalCfg, ctx context.Context) error { for _, dbCfg := range cfg.Databases { dbs = append(dbs, database.NewPostgres(dbCfg)) } - tester := tester.NewPostgres(tester.Config{ + tester := tester.New(tester.Config{ Databases: dbs, TestTimeout: cfg.TestTimeout, TestInterval: cfg.TestInterval, diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index 9169e55..abab19e 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -62,7 +62,7 @@ func serve(cfg *ServeCfg, ctx context.Context) error { for _, dbCfg := range cfg.Databases { dbs = append(dbs, database.NewPostgres(dbCfg)) } - tester := tester.NewPostgres(tester.Config{ + tester := tester.New(tester.Config{ Databases: dbs, TestTimeout: cfg.TestTimeout, TestInterval: cfg.TestInterval, diff --git a/cmd/setup/setup.go b/cmd/setup/setup.go index 05fbb20..b024c84 100644 --- a/cmd/setup/setup.go +++ b/cmd/setup/setup.go @@ -43,7 +43,7 @@ func setup(cfg *SetupCfg, ctx context.Context) error { for _, dbCfg := range cfg.Databases { dbs = append(dbs, database.NewPostgres(dbCfg)) } - tester := tester.NewPostgres(tester.Config{ + tester := tester.New(tester.Config{ Databases: dbs, }) log.Info().Msg("Setup tester") diff --git a/internal/tester/impl.go b/internal/tester/impl.go index 031a857..dc183be 100644 --- a/internal/tester/impl.go +++ b/internal/tester/impl.go @@ -9,24 +9,24 @@ import ( "github.com/rs/zerolog/log" ) -type Postgres struct { +type TesterImpl struct { results chan Result config Config } -func NewPostgres(config Config) Tester { - return &Postgres{ +func New(config Config) Tester { + return &TesterImpl{ results: make(chan Result), config: config, } } -func (p *Postgres) Run(ctx context.Context) chan Result { +func (p *TesterImpl) Run(ctx context.Context) chan Result { go p.run(ctx) return p.results } -func (p *Postgres) run(ctx context.Context) { +func (p *TesterImpl) run(ctx context.Context) { log.Info().Msg("Starting postgres tester") log.Debug().Msg("Starting database tests") for { @@ -49,7 +49,7 @@ func (p *Postgres) run(ctx context.Context) { } } -func (p *Postgres) runDatabaseTest(db database.Database, ctx context.Context) { +func (p *TesterImpl) runDatabaseTest(db database.Database, ctx context.Context) { result := Result{ Database: db.Identifier(), Connectable: false, @@ -108,7 +108,7 @@ func (p *Postgres) runDatabaseTest(db database.Database, ctx context.Context) { } } -func (p *Postgres) Setup(ctx context.Context) error { +func (p *TesterImpl) Setup(ctx context.Context) error { var setupErrors []error for _, db := range p.config.Databases { err := db.SetupTestTable(ctx) diff --git a/internal/tester/impl_test.go b/internal/tester/impl_test.go index dae1703..dec080e 100644 --- a/internal/tester/impl_test.go +++ b/internal/tester/impl_test.go @@ -16,7 +16,7 @@ func TestSetup(t *testing.T) { defer ctrl.Finish() mockDatabase := database.NewMockDatabase(ctrl) ctx := context.Background() - postgresTester := NewPostgres(Config{ + postgresTester := New(Config{ Databases: []database.Database{ mockDatabase, }, @@ -33,7 +33,7 @@ func TestSetupError(t *testing.T) { defer ctrl.Finish() mockDatabase := database.NewMockDatabase(ctrl) ctx := context.Background() - postgresTester := NewPostgres(Config{ + postgresTester := New(Config{ Databases: []database.Database{ mockDatabase, }, @@ -49,7 +49,7 @@ func TestRun(t *testing.T) { defer ctrl.Finish() mockDatabase := database.NewMockDatabase(ctrl) ctx, cancel := context.WithCancel(context.Background()) - postgresTester := NewPostgres(Config{ + postgresTester := New(Config{ TestTimeout: 1, TestInterval: 1, Databases: []database.Database{ @@ -62,7 +62,7 @@ func TestRun(t *testing.T) { mockDatabase.EXPECT().TestWrite(ctx).Return(nil) mockDatabase.EXPECT().Close().Return(nil) go postgresTester.Run(ctx) - result := <-postgresTester.(*Postgres).results + result := <-postgresTester.(*TesterImpl).results cancel() assert.Equal(t, "test", result.Database) assert.Equal(t, true, result.Connectable) @@ -75,7 +75,7 @@ func TestRunDatabaseTest(t *testing.T) { defer ctrl.Finish() mockDatabase := database.NewMockDatabase(ctrl) ctx, cancel := context.WithCancel(context.Background()) - postgresTester := NewPostgres(Config{ + postgresTester := New(Config{ TestTimeout: 1, TestInterval: 1, Databases: []database.Database{ @@ -87,8 +87,8 @@ func TestRunDatabaseTest(t *testing.T) { mockDatabase.EXPECT().TestRead(ctx).Return(nil) mockDatabase.EXPECT().TestWrite(ctx).Return(nil) mockDatabase.EXPECT().Close().Return(nil) - go postgresTester.(*Postgres).runDatabaseTest(mockDatabase, ctx) - result := <-postgresTester.(*Postgres).results + go postgresTester.(*TesterImpl).runDatabaseTest(mockDatabase, ctx) + result := <-postgresTester.(*TesterImpl).results cancel() assert.Equal(t, "test", result.Database) assert.Equal(t, true, result.Connectable) @@ -101,7 +101,7 @@ func TestRunDatabaseTestConnectError(t *testing.T) { defer ctrl.Finish() mockDatabase := database.NewMockDatabase(ctrl) ctx, cancel := context.WithCancel(context.Background()) - postgresTester := NewPostgres(Config{ + postgresTester := New(Config{ TestTimeout: 1, TestInterval: 1, Databases: []database.Database{ @@ -110,8 +110,8 @@ func TestRunDatabaseTestConnectError(t *testing.T) { }) mockDatabase.EXPECT().Identifier().Return("test") mockDatabase.EXPECT().Connect().Return(errors.New("Connect error")) - go postgresTester.(*Postgres).runDatabaseTest(mockDatabase, ctx) - result := <-postgresTester.(*Postgres).results + go postgresTester.(*TesterImpl).runDatabaseTest(mockDatabase, ctx) + result := <-postgresTester.(*TesterImpl).results cancel() assert.Equal(t, "test", result.Database) assert.Equal(t, false, result.Connectable) @@ -124,7 +124,7 @@ func TestRunDatabaseTestReadError(t *testing.T) { defer ctrl.Finish() mockDatabase := database.NewMockDatabase(ctrl) ctx, cancel := context.WithCancel(context.Background()) - postgresTester := NewPostgres(Config{ + postgresTester := New(Config{ TestTimeout: 1, TestInterval: 1, Databases: []database.Database{ @@ -135,8 +135,8 @@ func TestRunDatabaseTestReadError(t *testing.T) { mockDatabase.EXPECT().Connect().Return(nil) mockDatabase.EXPECT().TestRead(ctx).Return(errors.New("Read error")) mockDatabase.EXPECT().Close().Return(nil) - go postgresTester.(*Postgres).runDatabaseTest(mockDatabase, ctx) - result := <-postgresTester.(*Postgres).results + go postgresTester.(*TesterImpl).runDatabaseTest(mockDatabase, ctx) + result := <-postgresTester.(*TesterImpl).results cancel() assert.Equal(t, "test", result.Database) assert.Equal(t, true, result.Connectable) @@ -149,7 +149,7 @@ func TestRunDatabaseTestWriteError(t *testing.T) { defer ctrl.Finish() mockDatabase := database.NewMockDatabase(ctrl) ctx, cancel := context.WithCancel(context.Background()) - postgresTester := NewPostgres(Config{ + postgresTester := New(Config{ TestTimeout: 1, TestInterval: 1, Databases: []database.Database{ @@ -161,8 +161,8 @@ func TestRunDatabaseTestWriteError(t *testing.T) { mockDatabase.EXPECT().TestRead(ctx).Return(nil) mockDatabase.EXPECT().TestWrite(ctx).Return(errors.New("Write error")) mockDatabase.EXPECT().Close().Return(nil) - go postgresTester.(*Postgres).runDatabaseTest(mockDatabase, ctx) - result := <-postgresTester.(*Postgres).results + go postgresTester.(*TesterImpl).runDatabaseTest(mockDatabase, ctx) + result := <-postgresTester.(*TesterImpl).results cancel() assert.Equal(t, "test", result.Database) assert.Equal(t, true, result.Connectable)