Skip to content

Commit

Permalink
Add more tests, change if conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa committed Dec 4, 2023
1 parent 96e4f92 commit 3f9a1aa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions connection_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func isDml(v int64) bool {
}

func isDql(data *execResponseData) bool {
return data.StatementTypeID == statementTypeIDSelect && data.RowType[0].Name != "multiple statement execution"
return data.StatementTypeID == statementTypeIDSelect && !isMultiStmt(data)
}

func updateRows(data execResponseData) (int64, error) {
Expand Down Expand Up @@ -302,7 +302,7 @@ func (sc *snowflakeConn) setupOCSPPrivatelink(app string, host string) error {

func isStatementContext(ctx context.Context) bool {
v := ctx.Value(executionType)
if v != nil && v == executionTypeStatement {
if v == executionTypeStatement {

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Ubuntu

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Ubuntu

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Ubuntu

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.20 on Ubuntu

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Ubuntu

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.20 on Ubuntu

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Mac

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Mac

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.20 on Mac

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Mac

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.20 on Mac

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)

Check failure on line 305 in connection_util.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.20 on Mac

should use 'return v == executionTypeStatement' instead of 'if v == executionTypeStatement { return true }; return false' (S1008)
return true
}
return false
Expand Down
32 changes: 31 additions & 1 deletion statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@ func openConn(t *testing.T) *sql.Conn {

func TestExecStmt(t *testing.T) {
dqlQuery := "SELECT 1"
dmlQuery := "INSERT INTO TestDDLExec VALUES (1)"
ddlQuery := "CREATE OR REPLACE TABLE TestDDLExec (num NUMBER)"
multiStmtQuery := "DELETE FROM TestDDLExec;\n" +
"SELECT 1;\n" +
"SELECT 2;"
ctx := context.Background()
multiStmtCtx, err := WithMultiStatement(ctx, 3)
if err != nil {
t.Error(err)
}
runDBTest(t, func(dbt *DBTest) {
dbt.mustExec(ddlQuery)
defer dbt.mustExec("DROP TABLE IF EXISTS TestDDLExec")
testcases := []struct {
name string
Expand Down Expand Up @@ -79,6 +88,27 @@ func TestExecStmt(t *testing.T) {
return stmt.(driver.StmtExecContext).ExecContext(ctx, nil)
},
},
{
name: "dml Exec",
query: dmlQuery,
f: func(stmt driver.Stmt) (any, error) {
return stmt.Exec(nil)
},
},
{
name: "dml ExecContext",
query: dmlQuery,
f: func(stmt driver.Stmt) (any, error) {
return stmt.(driver.StmtExecContext).ExecContext(ctx, nil)
},
},
{
name: "multistmt ExecContext",
query: multiStmtQuery,
f: func(stmt driver.Stmt) (any, error) {
return stmt.(driver.StmtExecContext).ExecContext(multiStmtCtx, nil)
},
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -91,7 +121,7 @@ func TestExecStmt(t *testing.T) {
t.Error("queryId should be empty before executing any query")
}
if _, err := tc.f(stmt); err != nil {
t.Error("should have not failed to execute the query")
t.Errorf("should have not failed to execute the query, err: %s\n", err)
}
if stmt.(SnowflakeStmt).GetQueryID() == "" {
t.Error("should have set the query id")
Expand Down

0 comments on commit 3f9a1aa

Please sign in to comment.