Skip to content

Commit

Permalink
add unit test for bugfix sql nullable column error
Browse files Browse the repository at this point in the history
  • Loading branch information
felixgunawan committed Aug 7, 2023
1 parent 95dedae commit 28d4ec1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tools/sqldatabase/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package mysql_test

import (
"context"
"database/sql"
"fmt"
"os"
"testing"

Expand All @@ -28,4 +30,12 @@ func Test(t *testing.T) {
require.NoError(t, err)

t.Log(desc)

for _, tableName := range tbs {
_, err = db.Query(context.Background(), fmt.Sprintf("SELECT * from %s LIMIT 1", tableName))
if err == sql.ErrNoRows { // exclude no row error, since we only need to check if db.Query function can perform query correctly

Check failure on line 36 in tools/sqldatabase/mysql/mysql_test.go

View workflow job for this annotation

GitHub Actions / lint

line is 129 characters (lll)
continue
}
require.NoError(t, err)
}
}
11 changes: 11 additions & 0 deletions tools/sqldatabase/postgresql/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package postgresql_test

import (
"context"
"database/sql"
"fmt"
"os"
"testing"

Expand All @@ -27,4 +29,13 @@ func Test(t *testing.T) {
require.NoError(t, err)

t.Log(desc)

for _, tableName := range tbs {
_, err = db.Query(context.Background(), fmt.Sprintf("SELECT * from %s LIMIT 1", tableName))
if err == sql.ErrNoRows { // exclude no row error, since we only need to check if db.Query function can perform query correctly

Check failure on line 35 in tools/sqldatabase/postgresql/postgresql_test.go

View workflow job for this annotation

GitHub Actions / lint

line is 129 characters (lll)
continue
}
require.NoError(t, err)
}

Check failure on line 40 in tools/sqldatabase/postgresql/postgresql_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
}
9 changes: 9 additions & 0 deletions tools/sqldatabase/sqlite3/sqlite3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sqlite3_test
import (
"context"
"database/sql"
"fmt"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -46,4 +47,12 @@ func Test(t *testing.T) {
require.True(t, strings.Contains(desc, "Activity")) //nolint:stylecheck
require.True(t, strings.Contains(desc, "Activity1")) //nolint:stylecheck
require.True(t, strings.Contains(desc, "Activity2")) //nolint:stylecheck

for _, tableName := range tbs {
_, err = db.Query(context.Background(), fmt.Sprintf("SELECT * from %s LIMIT 1", tableName))
if err == sql.ErrNoRows { // exclude no row error, since we only need to check if db.Query function can perform query correctly

Check failure on line 53 in tools/sqldatabase/sqlite3/sqlite3_test.go

View workflow job for this annotation

GitHub Actions / lint

line is 129 characters (lll)
continue
}
require.NoError(t, err)
}
}

0 comments on commit 28d4ec1

Please sign in to comment.