Skip to content

Commit

Permalink
fix other test
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Dec 8, 2023
1 parent 0e6fdd4 commit 3043f78
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
1 change: 0 additions & 1 deletion flow/e2e/snowflake/peer_flow_sf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type PeerFlowE2ETestSuiteSF struct {
}

func TestPeerFlowE2ETestSuiteSF(t *testing.T) {
// The got.Each can also accept a function to init the g for each test case.
got.Each(t, func(t *testing.T) PeerFlowE2ETestSuiteSF {
g := got.New(t)

Expand Down
71 changes: 52 additions & 19 deletions flow/e2e/snowflake/snowflake_schema_delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,67 @@ package e2e_snowflake
import (
"context"
"fmt"
"testing"

connsnowflake "github.com/PeerDB-io/peer-flow/connectors/snowflake"
"github.com/PeerDB-io/peer-flow/generated/protos"
"github.com/PeerDB-io/peer-flow/model/qvalue"
"github.com/stretchr/testify/suite"
"github.com/sirupsen/logrus"
"github.com/ysmood/got"
)

const schemaDeltaTestSchemaName = "PUBLIC"

type SnowflakeSchemaDeltaTestSuite struct {
suite.Suite
got.G
t *testing.T

connector *connsnowflake.SnowflakeConnector
sfTestHelper *SnowflakeTestHelper
}

func (suite *SnowflakeSchemaDeltaTestSuite) failTestError(err error) {
func (suite SnowflakeSchemaDeltaTestSuite) failTestError(err error) {
if err != nil {
suite.FailNow(err.Error())
logrus.Errorf("Error in test: %v", err)
suite.FailNow()
}
}

func (suite *SnowflakeSchemaDeltaTestSuite) SetupSuite() {
var err error
func setupSchemaDeltaSuite(
t *testing.T,
g got.G,
) SnowflakeSchemaDeltaTestSuite {
sfTestHelper, err := NewSnowflakeTestHelper()
if err != nil {
logrus.Errorf("Error in test: %v", err)
t.FailNow()
}

suite.sfTestHelper, err = NewSnowflakeTestHelper()
suite.failTestError(err)
connector, err := connsnowflake.NewSnowflakeConnector(
context.Background(),
sfTestHelper.Config,
)
if err != nil {
logrus.Errorf("Error in test: %v", err)
t.FailNow()
}

suite.connector, err = connsnowflake.NewSnowflakeConnector(context.Background(),
suite.sfTestHelper.Config)
suite.failTestError(err)
return SnowflakeSchemaDeltaTestSuite{
G: g,
t: t,
connector: connector,
sfTestHelper: sfTestHelper,
}
}

func (suite *SnowflakeSchemaDeltaTestSuite) TearDownSuite() {
func (suite SnowflakeSchemaDeltaTestSuite) tearDownSuite() {
err := suite.sfTestHelper.Cleanup()
suite.failTestError(err)
err = suite.connector.Close()
suite.failTestError(err)
}

func (suite *SnowflakeSchemaDeltaTestSuite) TestSimpleAddColumn() {
func (suite SnowflakeSchemaDeltaTestSuite) TestSimpleAddColumn() {
tableName := fmt.Sprintf("%s.SIMPLE_ADD_COLUMN", schemaDeltaTestSchemaName)
err := suite.sfTestHelper.RunCommand(fmt.Sprintf("CREATE TABLE %s(ID TEXT PRIMARY KEY)", tableName))
suite.failTestError(err)
Expand Down Expand Up @@ -70,7 +91,7 @@ func (suite *SnowflakeSchemaDeltaTestSuite) TestSimpleAddColumn() {
}, output.TableNameSchemaMapping[tableName])
}

func (suite *SnowflakeSchemaDeltaTestSuite) TestAddAllColumnTypes() {
func (suite SnowflakeSchemaDeltaTestSuite) TestAddAllColumnTypes() {
tableName := fmt.Sprintf("%s.ADD_DROP_ALL_COLUMN_TYPES", schemaDeltaTestSchemaName)
err := suite.sfTestHelper.RunCommand(fmt.Sprintf("CREATE TABLE %s(ID TEXT PRIMARY KEY)", tableName))
suite.failTestError(err)
Expand Down Expand Up @@ -116,7 +137,7 @@ func (suite *SnowflakeSchemaDeltaTestSuite) TestAddAllColumnTypes() {
suite.Equal(expectedTableSchema, output.TableNameSchemaMapping[tableName])
}

func (suite *SnowflakeSchemaDeltaTestSuite) TestAddTrickyColumnNames() {
func (suite SnowflakeSchemaDeltaTestSuite) TestAddTrickyColumnNames() {
tableName := fmt.Sprintf("%s.ADD_DROP_TRICKY_COLUMN_NAMES", schemaDeltaTestSchemaName)
err := suite.sfTestHelper.RunCommand(fmt.Sprintf("CREATE TABLE %s(id TEXT PRIMARY KEY)", tableName))
suite.failTestError(err)
Expand Down Expand Up @@ -160,7 +181,7 @@ func (suite *SnowflakeSchemaDeltaTestSuite) TestAddTrickyColumnNames() {
suite.Equal(expectedTableSchema, output.TableNameSchemaMapping[tableName])
}

func (suite *SnowflakeSchemaDeltaTestSuite) TestAddWhitespaceColumnNames() {
func (suite SnowflakeSchemaDeltaTestSuite) TestAddWhitespaceColumnNames() {
tableName := fmt.Sprintf("%s.ADD_DROP_WHITESPACE_COLUMN_NAMES", schemaDeltaTestSchemaName)
err := suite.sfTestHelper.RunCommand(fmt.Sprintf("CREATE TABLE %s(\" \" TEXT PRIMARY KEY)", tableName))
suite.failTestError(err)
Expand Down Expand Up @@ -198,6 +219,18 @@ func (suite *SnowflakeSchemaDeltaTestSuite) TestAddWhitespaceColumnNames() {
suite.Equal(expectedTableSchema, output.TableNameSchemaMapping[tableName])
}

// func TestSnowflakeSchemaDeltaTestSuite(t *testing.T) {
// suite.Run(t, new(SnowflakeSchemaDeltaTestSuite))
// }
func TestSnowflakeSchemaDeltaTestSuite(t *testing.T) {
got.Each(t, func(t *testing.T) SnowflakeSchemaDeltaTestSuite {
g := got.New(t)

g.Parallel()

suite := setupSchemaDeltaSuite(t, g)

g.Cleanup(func() {
suite.tearDownSuite()
})

return suite
})
}

0 comments on commit 3043f78

Please sign in to comment.