Skip to content

Commit

Permalink
fix: wrong usage of testify Equal() function (#1379)
Browse files Browse the repository at this point in the history
* fix: wring usage of t.Equal with testify pkg (resources)

* fix: wring usage of t.Equal with testify pkg (snowflake)
  • Loading branch information
mnagaa authored Dec 7, 2022
1 parent b0e6580 commit 476b330
Show file tree
Hide file tree
Showing 39 changed files with 229 additions and 225 deletions.
4 changes: 2 additions & 2 deletions pkg/resources/database_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func TestDatabaseGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())

shares := d.Get("shares").(*schema.Set)
r.True(shares.Contains("test-share-1"))
r.True(shares.Contains("test-share-2"))
r.Equal(shares.Len(), 2)
r.Equal(2, shares.Len())
}

func expectReadDatabaseGrant(mock sqlmock.Sqlmock) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/external_table_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ func TestExternalTableGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())

shares := d.Get("shares").(*schema.Set)
r.True(shares.Contains("test-share-1"))
r.True(shares.Contains("test-share-2"))
r.Equal(shares.Len(), 2)
r.Equal(2, shares.Len())
}

func expectReadExternalTableGrant(mock sqlmock.Sqlmock) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/file_format_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestFileFormatGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())
}

func expectReadFileFormatGrant(mock sqlmock.Sqlmock) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/function_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func TestFunctionGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())

shares := d.Get("shares").(*schema.Set)
r.True(shares.Contains("test-share-1"))
r.True(shares.Contains("test-share-2"))
r.Equal(shares.Len(), 2)
r.Equal(2, shares.Len())
}

func expectReadFunctionGrant(mock sqlmock.Sqlmock) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/list_expansion_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ func TestExpandBlankStringList(t *testing.T) {
in := []interface{}{}
out := expandStringList(in)

r.Equal(len(out), 0)
r.Equal(0, len(out))
}
2 changes: 1 addition & 1 deletion pkg/resources/masking_policy_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestMaskingPolicyGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())
}

func expectReadMaskingPolicyGrant(mock sqlmock.Sqlmock) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/materialized_view_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ func TestMaterializedViewGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())

shares := d.Get("shares").(*schema.Set)
r.True(shares.Contains("test-share-1"))
r.True(shares.Contains("test-share-2"))
r.Equal(shares.Len(), 2)
r.Equal(2, shares.Len())
}

func expectReadMaterializedViewGrant(mock sqlmock.Sqlmock) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/pipe_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestPipeGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())
}

func expectReadPipeGrant(mock sqlmock.Sqlmock) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/procedure_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func TestProcedureGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())

shares := d.Get("shares").(*schema.Set)
r.True(shares.Contains("test-share-1"))
r.True(shares.Contains("test-share-2"))
r.Equal(shares.Len(), 2)
r.Equal(2, shares.Len())
}

func expectReadProcedureGrant(mock sqlmock.Sqlmock) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/row_access_policy_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestRowAccessPolicyGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())
}

func expectReadRowAccessPolicyGrant(mock sqlmock.Sqlmock) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/schema_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ func TestSchemaGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())

shares := d.Get("shares").(*schema.Set)
r.True(shares.Contains("test-share-1"))
r.True(shares.Contains("test-share-2"))
r.Equal(shares.Len(), 2)
r.Equal(2, shares.Len())
}

func expectReadSchemaGrant(mock sqlmock.Sqlmock, testPriv string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/sequence_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestSequenceGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())
}

func expectReadSequenceGrant(mock sqlmock.Sqlmock) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/stage_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestStageGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())
}

func expectReadStageGrant(mock sqlmock.Sqlmock, testPriv string) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/stream_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestStreamGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())
}

func expectReadStreamGrant(mock sqlmock.Sqlmock) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/table_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ func TestTableGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())

shares := d.Get("shares").(*schema.Set)
r.True(shares.Contains("test-share-1"))
r.True(shares.Contains("test-share-2"))
r.Equal(shares.Len(), 2)
r.Equal(2, shares.Len())
}

func expectReadTableGrant(mock sqlmock.Sqlmock) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/tag_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestTagGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())
}

func expectReadTagGrant(mock sqlmock.Sqlmock) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/task_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestTaskGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())
}

func expectReadTaskGrant(mock sqlmock.Sqlmock) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/task_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestStringFromTaskID(t *testing.T) {
task := taskID{DatabaseName: "test_db", SchemaName: "test_schema", TaskName: "test_task"}
id, err := task.String()
r.NoError(err)
r.Equal(id, "test_db|test_schema|test_task")
r.Equal("test_db|test_schema|test_task", id)
}

func TestTaskIDFromString(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/view_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ func TestViewGrantRead(t *testing.T) {
roles := d.Get("roles").(*schema.Set)
r.True(roles.Contains("test-role-1"))
r.True(roles.Contains("test-role-2"))
r.Equal(roles.Len(), 2)
r.Equal(2, roles.Len())

shares := d.Get("shares").(*schema.Set)
r.True(shares.Contains("test-share-1"))
r.True(shares.Contains("test-share-2"))
r.Equal(shares.Len(), 2)
r.Equal(2, shares.Len())
}

func expectReadViewGrant(mock sqlmock.Sqlmock) {
Expand Down
8 changes: 5 additions & 3 deletions pkg/snowflake/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ func TestListDatabases(t *testing.T) {
func TestEnableReplicationAccounts(t *testing.T) {
r := require.New(t)
db := snowflake.Database("good_name")
r.Equal(db.EnableReplicationAccounts("good_name", "account1"), `ALTER DATABASE "good_name" ENABLE REPLICATION TO ACCOUNTS account1`)
expected := `ALTER DATABASE "good_name" ENABLE REPLICATION TO ACCOUNTS account1`
r.Equal(expected, db.EnableReplicationAccounts("good_name", "account1"))
}

func TestDisableReplicationAccounts(t *testing.T) {
r := require.New(t)
db := snowflake.Database("good_name")
r.Equal(db.DisableReplicationAccounts("good_name", "account1"), `ALTER DATABASE "good_name" DISABLE REPLICATION TO ACCOUNTS account1`)
expected := `ALTER DATABASE "good_name" DISABLE REPLICATION TO ACCOUNTS account1`
r.Equal(expected, db.DisableReplicationAccounts("good_name", "account1"))
}

func TestGetRemovedAccountsFromReplicationConfiguration(t *testing.T) {
Expand All @@ -148,5 +150,5 @@ func TestGetRemovedAccountsFromReplicationConfiguration(t *testing.T) {
oldAccounts := []interface{}{"acc1", "acc2", "acc3"}
newAccounts := []interface{}{"acc1", "acc2"}

r.Equal(db.GetRemovedAccountsFromReplicationConfiguration(oldAccounts, newAccounts), []interface{}{"acc3"})
r.Equal([]interface{}{"acc3"}, db.GetRemovedAccountsFromReplicationConfiguration(oldAccounts, newAccounts))
}
13 changes: 7 additions & 6 deletions pkg/snowflake/external_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,27 @@ func TestExternalFunctionCreate(t *testing.T) {
s.WithAPIIntegration("test_api_integration_01")
s.WithURLOfProxyAndResource("https://123456.execute-api.us-west-2.amazonaws.com/prod/test_func")

r.Equal(s.QualifiedName(), `"test_db"."test_schema"."test_function"`)
r.Equal(s.QualifiedNameWithArgTypes(), `"test_db"."test_schema"."test_function" (varchar)`)
r.Equal(`"test_db"."test_schema"."test_function"`, s.QualifiedName())
r.Equal(`"test_db"."test_schema"."test_function" (varchar)`, s.QualifiedNameWithArgTypes())

r.Equal(s.Create(), `CREATE EXTERNAL FUNCTION "test_db"."test_schema"."test_function" (data varchar) RETURNS varchar NULL RETURNS NULL ON NULL INPUT IMMUTABLE API_INTEGRATION = 'test_api_integration_01' AS 'https://123456.execute-api.us-west-2.amazonaws.com/prod/test_func'`)
expected := `CREATE EXTERNAL FUNCTION "test_db"."test_schema"."test_function" (data varchar) RETURNS varchar NULL RETURNS NULL ON NULL INPUT IMMUTABLE API_INTEGRATION = 'test_api_integration_01' AS 'https://123456.execute-api.us-west-2.amazonaws.com/prod/test_func'`
r.Equal(expected, s.Create())
}

func TestExternalFunctionDrop(t *testing.T) {
r := require.New(t)

// Without arg
s := ExternalFunction("test_function", "test_db", "test_schema")
r.Equal(s.Drop(), `DROP FUNCTION "test_db"."test_schema"."test_function" ()`)
r.Equal(`DROP FUNCTION "test_db"."test_schema"."test_function" ()`, s.Drop())

// With arg
s = ExternalFunction("test_function", "test_db", "test_schema").WithArgTypes("varchar")
r.Equal(s.Drop(), `DROP FUNCTION "test_db"."test_schema"."test_function" (varchar)`)
r.Equal(`DROP FUNCTION "test_db"."test_schema"."test_function" (varchar)`, s.Drop())
}

func TestExternalFunctionShow(t *testing.T) {
r := require.New(t)
s := ExternalFunction("test_function", "test_db", "test_schema")
r.Equal(s.Show(), `SHOW EXTERNAL FUNCTIONS LIKE 'test_function' IN SCHEMA "test_db"."test_schema"`)
r.Equal(`SHOW EXTERNAL FUNCTIONS LIKE 'test_function' IN SCHEMA "test_db"."test_schema"`, s.Show())
}
13 changes: 7 additions & 6 deletions pkg/snowflake/external_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,30 @@ func TestExternalTableCreate(t *testing.T) {
s.WithLocation("location")
s.WithPattern("pattern")
s.WithFileFormat("TYPE = CSV FIELD_DELIMITER = '|'")
r.Equal(s.QualifiedName(), `"test_db"."test_schema"."test_table"`)
r.Equal(`"test_db"."test_schema"."test_table"`, s.QualifiedName())

r.Equal(s.Create(), `CREATE EXTERNAL TABLE "test_db"."test_schema"."test_table" ("column1" OBJECT AS expression1, "column2" VARCHAR AS expression2) WITH LOCATION = location REFRESH_ON_CREATE = false AUTO_REFRESH = false PATTERN = 'pattern' FILE_FORMAT = ( TYPE = CSV FIELD_DELIMITER = '|' )`)
r.Equal(`CREATE EXTERNAL TABLE "test_db"."test_schema"."test_table" ("column1" OBJECT AS expression1, "column2" VARCHAR AS expression2) WITH LOCATION = location REFRESH_ON_CREATE = false AUTO_REFRESH = false PATTERN = 'pattern' FILE_FORMAT = ( TYPE = CSV FIELD_DELIMITER = '|' )`, s.Create())

s.WithComment("Test Comment")
r.Equal(s.Create(), `CREATE EXTERNAL TABLE "test_db"."test_schema"."test_table" ("column1" OBJECT AS expression1, "column2" VARCHAR AS expression2) WITH LOCATION = location REFRESH_ON_CREATE = false AUTO_REFRESH = false PATTERN = 'pattern' FILE_FORMAT = ( TYPE = CSV FIELD_DELIMITER = '|' ) COMMENT = 'Test Comment'`)
r.Equal(`CREATE EXTERNAL TABLE "test_db"."test_schema"."test_table" ("column1" OBJECT AS expression1, "column2" VARCHAR AS expression2) WITH LOCATION = location REFRESH_ON_CREATE = false AUTO_REFRESH = false PATTERN = 'pattern' FILE_FORMAT = ( TYPE = CSV FIELD_DELIMITER = '|' ) COMMENT = 'Test Comment'`, s.Create())
}

func TestExternalTableUpdate(t *testing.T) {
r := require.New(t)
s := ExternalTable("test_table", "test_db", "test_schema")
s.WithTags([]TagValue{{Name: "tag1", Value: "value1", Schema: "test_schema", Database: "test_db"}})
r.Equal(s.Update(), `ALTER EXTERNAL TABLE "test_db"."test_schema"."test_table" TAG "test_db"."test_schema"."tag1" = "value1"`)
expected := `ALTER EXTERNAL TABLE "test_db"."test_schema"."test_table" TAG "test_db"."test_schema"."tag1" = "value1"`
r.Equal(expected, s.Update())
}

func TestExternalTableDrop(t *testing.T) {
r := require.New(t)
s := ExternalTable("test_table", "test_db", "test_schema")
r.Equal(s.Drop(), `DROP EXTERNAL TABLE "test_db"."test_schema"."test_table"`)
r.Equal(`DROP EXTERNAL TABLE "test_db"."test_schema"."test_table"`, s.Drop())
}

func TestExternalTableShow(t *testing.T) {
r := require.New(t)
s := ExternalTable("test_table", "test_db", "test_schema")
r.Equal(s.Show(), `SHOW EXTERNAL TABLES LIKE 'test_table' IN SCHEMA "test_db"."test_schema"`)
r.Equal(`SHOW EXTERNAL TABLES LIKE 'test_table' IN SCHEMA "test_db"."test_schema"`, s.Show())
}
4 changes: 2 additions & 2 deletions pkg/snowflake/file_format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func TestFileFormatCreateCSV(t *testing.T) {
r := require.New(t)
f := FileFormat("test_file_format", "test_db", "test_schema")
r.Equal(f.QualifiedName(), `"test_db"."test_schema"."test_file_format"`)
r.Equal(`"test_db"."test_schema"."test_file_format"`, f.QualifiedName())

f.WithFormatType("CSV")
f.WithCompression("AUTO")
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestFileFormatCreateCSV(t *testing.T) {
func TestFileFormatCreateJSON(t *testing.T) {
r := require.New(t)
f := FileFormat("test_file_format_json", "test_db", "test_schema")
r.Equal(f.QualifiedName(), `"test_db"."test_schema"."test_file_format_json"`)
r.Equal(`"test_db"."test_schema"."test_file_format_json"`, f.QualifiedName())

f.WithFormatType("JSON")
f.WithCompression("AUTO")
Expand Down
4 changes: 2 additions & 2 deletions pkg/snowflake/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestFunctionDrop(t *testing.T) {
// Without arg
s := getJavaScriptFuction(false)
stmnt, _ := s.Drop()
r.Equal(stmnt, `DROP FUNCTION "test_db"."test_schema"."test_func"()`)
r.Equal(`DROP FUNCTION "test_db"."test_schema"."test_func"()`, stmnt)

// With arg
ss := getJavaScriptFuction(true)
Expand All @@ -231,7 +231,7 @@ func TestFunctionShow(t *testing.T) {
r := require.New(t)
s := getJavaScriptFuction(false)
stmnt := s.Show()
r.Equal(stmnt, `SHOW USER FUNCTIONS LIKE 'test_func' IN SCHEMA "test_db"."test_schema"`)
r.Equal(`SHOW USER FUNCTIONS LIKE 'test_func' IN SCHEMA "test_db"."test_schema"`, stmnt)
}

func TestFunctionRename(t *testing.T) {
Expand Down
Loading

0 comments on commit 476b330

Please sign in to comment.