Skip to content

Commit

Permalink
don't use got.New
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Dec 22, 2023
1 parent de34287 commit c823474
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 82 deletions.
14 changes: 6 additions & 8 deletions flow/e2e/bigquery/peer_flow_bq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
)

type PeerFlowE2ETestSuiteBQ struct {
got.G
t *testing.T

bqSuffix string
Expand Down Expand Up @@ -102,7 +101,7 @@ func setupBigQuery(t *testing.T) *BigQueryTestHelper {
}

// Implement SetupAllSuite interface to setup the test suite
func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuiteBQ {
func setupSuite(t *testing.T) PeerFlowE2ETestSuiteBQ {
err := godotenv.Load()
if err != nil {
// it's okay if the .env file is not present
Expand All @@ -122,7 +121,6 @@ func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuiteBQ {
bq := setupBigQuery(t)

return PeerFlowE2ETestSuiteBQ{
G: g,
t: t,
bqSuffix: bqSuffix,
pool: pool,
Expand All @@ -134,13 +132,13 @@ func (s PeerFlowE2ETestSuiteBQ) TearDownSuite() {
err := e2e.TearDownPostgres(s.pool, s.bqSuffix)
if err != nil {
slog.Error("failed to tear down postgres", slog.Any("error", err))
s.FailNow()
s.t.FailNow()
}

err = s.bqHelper.DropDataset()
if err != nil {
slog.Error("failed to tear down bigquery", slog.Any("error", err))
s.FailNow()
s.t.FailNow()
}
}

Expand Down Expand Up @@ -316,7 +314,7 @@ func (s PeerFlowE2ETestSuiteBQ) Test_Complete_Simple_Flow_BQ() {

count, err := s.bqHelper.countRows(dstTableName)
require.NoError(s.t, err)
s.Equal(10, count)
require.Equal(s.t, 10, count)

// TODO: verify that the data is correctly synced to the destination table
// on the bigquery side
Expand Down Expand Up @@ -798,8 +796,8 @@ func (s PeerFlowE2ETestSuiteBQ) Test_Multi_Table_BQ() {
count2, err := s.bqHelper.countRows(dstTable2Name)
require.NoError(s.t, err)

s.Equal(1, count1)
s.Equal(1, count2)
require.Equal(s.t, 1, count1)
require.Equal(s.t, 1, count2)

env.AssertExpectations(s.t)
}
Expand Down
3 changes: 1 addition & 2 deletions flow/e2e/postgres/qrep_flow_pg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestPeerFlowE2ETestSuitePG(t *testing.T) {
got.Each(t, e2eshared.GotSuite(setupSuite))
}

func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuitePG {
func setupSuite(t *testing.T) PeerFlowE2ETestSuitePG {
err := godotenv.Load()
if err != nil {
// it's okay if the .env file is not present
Expand All @@ -59,7 +59,6 @@ func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuitePG {
}, false)
require.NoError(t, err)
return PeerFlowE2ETestSuitePG{
G: g,
t: t,
pool: pool,
peer: peer,
Expand Down
4 changes: 1 addition & 3 deletions flow/e2e/s3/qrep_flow_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
)

type PeerFlowE2ETestSuiteS3 struct {
got.G
t *testing.T

pool *pgxpool.Pool
Expand All @@ -41,7 +40,7 @@ func setupS3(mode string) (*S3TestHelper, error) {
return NewS3TestHelper(mode == "gcs")
}

func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuiteS3 {
func setupSuite(t *testing.T) PeerFlowE2ETestSuiteS3 {
err := godotenv.Load()
if err != nil {
// it's okay if the .env file is not present
Expand All @@ -61,7 +60,6 @@ func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuiteS3 {
}

return PeerFlowE2ETestSuiteS3{
G: g,
t: t,
pool: pool,
s3Helper: helper,
Expand Down
50 changes: 24 additions & 26 deletions flow/e2e/snowflake/peer_flow_sf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
)

type PeerFlowE2ETestSuiteSF struct {
got.G
t *testing.T

pgSuffix string
Expand All @@ -45,7 +44,7 @@ func (s PeerFlowE2ETestSuiteSF) attachSuffix(input string) string {
return fmt.Sprintf("%s_%s", input, s.pgSuffix)
}

func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuiteSF {
func setupSuite(t *testing.T) PeerFlowE2ETestSuiteSF {
err := godotenv.Load()
if err != nil {
// it's okay if the .env file is not present
Expand All @@ -60,13 +59,13 @@ func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuiteSF {
pool, err := e2e.SetupPostgres(pgSuffix)
if err != nil || pool == nil {
slog.Error("failed to setup Postgres", slog.Any("error", err))
g.FailNow()
t.FailNow()
}

sfHelper, err := NewSnowflakeTestHelper()
if err != nil {
slog.Error("failed to setup Snowflake", slog.Any("error", err))
g.FailNow()
t.FailNow()
}

connector, err := connsnowflake.NewSnowflakeConnector(
Expand All @@ -76,7 +75,6 @@ func setupSuite(t *testing.T, g got.G) PeerFlowE2ETestSuiteSF {
require.NoError(t, err)

suite := PeerFlowE2ETestSuiteSF{
G: g,
t: t,
pgSuffix: pgSuffix,
pool: pool,
Expand All @@ -92,22 +90,22 @@ func (s PeerFlowE2ETestSuiteSF) TearDownSuite() {
err := e2e.TearDownPostgres(s.pool, s.pgSuffix)
if err != nil {
slog.Error("failed to tear down Postgres", slog.Any("error", err))
s.FailNow()
s.t.FailNow()
}

if s.sfHelper != nil {
err = s.sfHelper.Cleanup()
if err != nil {
slog.Error("failed to tear down Snowflake", slog.Any("error", err))
s.FailNow()
s.t.FailNow()
}
}

err = s.connector.Close()

if err != nil {
slog.Error("failed to close Snowflake connector", slog.Any("error", err))
s.FailNow()
s.t.FailNow()
}
}

Expand Down Expand Up @@ -169,7 +167,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Complete_Simple_Flow_SF() {

count, err := s.sfHelper.CountRows("test_simple_flow_sf")
require.NoError(s.t, err)
s.Equal(20, count)
require.Equal(s.t, 20, count)

// check the number of rows where _PEERDB_SYNCED_AT is newer than 5 mins ago
// it should match the count.
Expand All @@ -178,7 +176,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Complete_Simple_Flow_SF() {
`, dstTableName)
numNewRows, err := s.sfHelper.RunIntQuery(newerSyncedAtQuery)
require.NoError(s.t, err)
s.Equal(20, numNewRows)
require.Equal(s.t, 20, numNewRows)

// TODO: verify that the data is correctly synced to the destination table
// on the Snowflake side
Expand Down Expand Up @@ -247,7 +245,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Flow_ReplicaIdentity_Index_No_Pkey() {

count, err := s.sfHelper.CountRows("test_replica_identity_no_pkey")
require.NoError(s.t, err)
s.Equal(20, count)
require.Equal(s.t, 20, count)

env.AssertExpectations(s.t)
}
Expand Down Expand Up @@ -325,11 +323,11 @@ func (s PeerFlowE2ETestSuiteSF) Test_Invalid_Geo_SF_Avro_CDC() {
// They should have been filtered out as null on destination
lineCount, err := s.sfHelper.CountNonNullRows("test_invalid_geo_sf_avro_cdc", "line")
require.NoError(s.t, err)
s.Equal(6, lineCount)
require.Equal(s.t, 6, lineCount)

polyCount, err := s.sfHelper.CountNonNullRows("test_invalid_geo_sf_avro_cdc", "poly")
require.NoError(s.t, err)
s.Equal(6, polyCount)
require.Equal(s.t, 6, polyCount)

// TODO: verify that the data is correctly synced to the destination table
// on the bigquery side
Expand Down Expand Up @@ -452,7 +450,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Toast_Nochanges_SF() {

if err != nil {
slog.Error("Error executing transaction", slog.Any("error", err))
s.FailNow()
s.t.FailNow()
}

wg.Done()
Expand Down Expand Up @@ -752,7 +750,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Types_SF() {
fmt.Println("error %w", err)
}
// Make sure that there are no nulls
s.Equal(noNulls, true)
require.Equal(s.t, noNulls, true)

env.AssertExpectations(s.t)
}
Expand Down Expand Up @@ -810,8 +808,8 @@ func (s PeerFlowE2ETestSuiteSF) Test_Multi_Table_SF() {
count2, err := s.sfHelper.CountRows("test2_sf")
require.NoError(s.t, err)

s.Equal(1, count1)
s.Equal(1, count2)
require.Equal(s.t, 1, count1)
require.Equal(s.t, 1, count2)

env.AssertExpectations(s.t)
}
Expand Down Expand Up @@ -871,7 +869,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Simple_Schema_Changes_SF() {
TableIdentifiers: []string{dstTableName},
})
require.NoError(s.t, err)
s.Equal(expectedTableSchema, output.TableNameSchemaMapping[dstTableName])
require.Equal(s.t, expectedTableSchema, output.TableNameSchemaMapping[dstTableName])
s.compareTableContentsSF("test_simple_schema_changes", "id,c1", false)

// alter source table, add column c2 and insert another row.
Expand Down Expand Up @@ -900,7 +898,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Simple_Schema_Changes_SF() {
TableIdentifiers: []string{dstTableName},
})
require.NoError(s.t, err)
s.Equal(expectedTableSchema, output.TableNameSchemaMapping[dstTableName])
require.Equal(s.t, expectedTableSchema, output.TableNameSchemaMapping[dstTableName])
s.compareTableContentsSF("test_simple_schema_changes", "id,c1,c2", false)

// alter source table, add column c3, drop column c2 and insert another row.
Expand Down Expand Up @@ -930,7 +928,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Simple_Schema_Changes_SF() {
TableIdentifiers: []string{dstTableName},
})
require.NoError(s.t, err)
s.Equal(expectedTableSchema, output.TableNameSchemaMapping[dstTableName])
require.Equal(s.t, expectedTableSchema, output.TableNameSchemaMapping[dstTableName])
s.compareTableContentsSF("test_simple_schema_changes", "id,c1,c3", false)

// alter source table, drop column c3 and insert another row.
Expand Down Expand Up @@ -960,7 +958,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Simple_Schema_Changes_SF() {
TableIdentifiers: []string{dstTableName},
})
require.NoError(s.t, err)
s.Equal(expectedTableSchema, output.TableNameSchemaMapping[dstTableName])
require.Equal(s.t, expectedTableSchema, output.TableNameSchemaMapping[dstTableName])
s.compareTableContentsSF("test_simple_schema_changes", "id,c1", false)
}()

Expand Down Expand Up @@ -1276,8 +1274,8 @@ func (s PeerFlowE2ETestSuiteSF) Test_Column_Exclusion() {
for _, field := range sfRows.Schema.Fields {
require.NotEqual(s.t, field.Name, "c2")
}
s.Equal(5, len(sfRows.Schema.Fields))
s.Equal(10, len(sfRows.Records))
require.Equal(s.t, 5, len(sfRows.Schema.Fields))
require.Equal(s.t, 10, len(sfRows.Records))
}

func (s PeerFlowE2ETestSuiteSF) Test_Soft_Delete_Basic() {
Expand Down Expand Up @@ -1447,7 +1445,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Soft_Delete_IUD_Same_Batch() {
SELECT COUNT(*) FROM %s WHERE _PEERDB_IS_DELETED = TRUE`, dstTableName)
numNewRows, err := s.sfHelper.RunIntQuery(newerSyncedAtQuery)
require.NoError(s.t, err)
s.Equal(1, numNewRows)
require.Equal(s.t, 1, numNewRows)
}

func (s PeerFlowE2ETestSuiteSF) Test_Soft_Delete_UD_Same_Batch() {
Expand Down Expand Up @@ -1534,7 +1532,7 @@ func (s PeerFlowE2ETestSuiteSF) Test_Soft_Delete_UD_Same_Batch() {
SELECT COUNT(*) FROM %s WHERE _PEERDB_IS_DELETED = TRUE`, dstTableName)
numNewRows, err := s.sfHelper.RunIntQuery(newerSyncedAtQuery)
require.NoError(s.t, err)
s.Equal(1, numNewRows)
require.Equal(s.t, 1, numNewRows)
}

func (s PeerFlowE2ETestSuiteSF) Test_Soft_Delete_Insert_After_Delete() {
Expand Down Expand Up @@ -1609,5 +1607,5 @@ func (s PeerFlowE2ETestSuiteSF) Test_Soft_Delete_Insert_After_Delete() {
SELECT COUNT(*) FROM %s WHERE _PEERDB_IS_DELETED = TRUE`, dstTableName)
numNewRows, err := s.sfHelper.RunIntQuery(newerSyncedAtQuery)
require.NoError(s.t, err)
s.Equal(0, numNewRows)
require.Equal(s.t, 0, numNewRows)
}
Loading

0 comments on commit c823474

Please sign in to comment.