forked from bitcomplete/sqltestutil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from hostwithquantum/tests
Tests
- Loading branch information
Showing
6 changed files
with
117 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: ci | ||
|
||
on: pull_request | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
- run: go test --race -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ package sqltestutil | |
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
|
||
"github.com/go-yaml/yaml" | ||
|
@@ -14,26 +14,26 @@ import ( | |
// db. Top-level keys in the YAML are treated as table names having repeated | ||
// rows, where keys on each row are column names. For example: | ||
// | ||
// users: | ||
// - id: 1 | ||
// name: Alice | ||
// email: [email protected] | ||
// - id: 2 | ||
// name: Bob | ||
// email: [email protected] | ||
// users: | ||
// - id: 1 | ||
// name: Alice | ||
// email: [email protected] | ||
// - id: 2 | ||
// name: Bob | ||
// email: [email protected] | ||
// | ||
// posts: | ||
// - user_id: 1 | ||
// title: Hello, world! | ||
// - user_id: 2 | ||
// title: Goodbye, world! | ||
// is_draft: true | ||
// posts: | ||
// - user_id: 1 | ||
// title: Hello, world! | ||
// - user_id: 2 | ||
// title: Goodbye, world! | ||
// is_draft: true | ||
// | ||
// The above would populate the users and posts tables. Fields that are missing | ||
// from the YAML are left out of the INSERT statement, and so are populated with | ||
// the default value for that column. | ||
func LoadScenario(ctx context.Context, db sqlx.ExtContext, filename string) error { | ||
data, err := ioutil.ReadFile(filename) | ||
data, err := os.ReadFile(filename) | ||
if err != nil { | ||
return err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package sqltestutil_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/bitcomplete/sqltestutil" | ||
"github.com/jackc/pgx/v5" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type ContainerTestSuite struct { | ||
suite.Suite | ||
|
||
pgContainer *sqltestutil.PostgresContainer | ||
} | ||
|
||
func (s *ContainerTestSuite) TestContainer() { | ||
s.T().Run("connection", func(t *testing.T) { | ||
dsn := s.pgContainer.ConnectionString() | ||
s.NotEmpty(dsn) | ||
}) | ||
|
||
s.T().Run("ping", func(t *testing.T) { | ||
conn, err := pgx.Connect(context.TODO(), s.pgContainer.ConnectionString()) | ||
s.NoError(err) | ||
s.NoError(conn.Ping(context.TODO())) | ||
}) | ||
} | ||
|
||
func TestContainerSuite(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
pg, _ := sqltestutil.StartPostgresContainer(context.Background(), "14") | ||
defer pg.Shutdown(ctx) | ||
|
||
suite.Run(t, &ContainerTestSuite{ | ||
pgContainer: pg, | ||
}) | ||
} |