Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update integration test suite #713

Merged
merged 21 commits into from
Mar 14, 2024
Merged

Update integration test suite #713

merged 21 commits into from
Mar 14, 2024

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented Mar 10, 2024

This PR restructures the integration tests (formally named e2e) and moves it into its own Go module.

There are a few things I didn't like about the previous setup:

  1. In CI, each database integration ran in its own GitHub Action workflow job. This means we were waiting for GitHub runners to become available, and were often waiting in a queue.

Instead, we now have a single job which runs all the integration tests in parallel. Yes, we'll reach some upper limit on how many containers can be run at once, but so far it has been consistently running in <2min which is fairly nice. We may even want to consider running the integration tests only on merge to main, with a manual dispatch.

  1. The github.com/pressly/goose/v3 Go module contained go.mod dependencies not required by the main module. All the drivers, container setup (namely testdb) and test utils are unnecessary.

I know this doesn't have a significant implication on consumer builds, but it's overall cleaner (IMO).

  1. In the future I'd like to seriously consider Split goose into separate modules (same repository) #664, which would allow us to fully purge the drivers from the goose library. Making for an overall improved experience.

Changes

  • Create a new go.mod in ./internal/testing/integration
  • Move testdb into this new module, updating dependencies
  • Bring in github.com/stretchr/testify, this is so widely used I've kind of given up trying to fight it
  • Factor out the common test, which can be reused by ALL databases. A combination of up, down, up with assertions at each step
  • To add a new test simple add a TestInsertDatabaseName and then add the corresponding migration files into internal/testing/integration/testdata/migrations/<insert_database_name>
  • Note, to test goose changes, there are 2 helpful commands: make add-gowork and make remove-gowork. This allows you to use the local goose library directly. This leverages go module workspaces

The tests run fairly quickly on my M1 machine, taking ~24s. The longest test can be improved, and I have plans for that. Vertica does take longer, but that's fine.

CleanShot 2024-03-14 at 08 55 01@2x

github.com/mfridman/interpolate v0.0.2
github.com/microsoft/go-mssqldb v1.6.0
github.com/ory/dockertest/v3 v3.10.0
Copy link
Collaborator Author

@mfridman mfridman Mar 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want the main goose module to have no dependency on this and any of the indirect deps. I think removing it and having an independent "integration test" module is cleaner.

# Conflicts:
#	.github/workflows/lint.yaml
#	Makefile
#	go.mod
#	go.sum
#	internal/testing/integration/testdata/migrations/duckdb/00001_table.sql
#	internal/testing/integration/testdata/migrations/duckdb/00003_alter.sql
#	internal/testing/integration/testdata/migrations/duckdb/00004_empty.sql
#	internal/testing/integration/testdata/migrations/ydb/00002_b.sql
#	internal/testing/integration/testdata/migrations/ydb/00003_c.sql
#	internal/testing/integration/testdata/migrations/ydb/00005_e.sql
#	internal/testing/testdb/duckdb.go
#	tests/e2e/main_test.go
#	tests/e2e/migrations_test.go
@mfridman mfridman marked this pull request as ready for review March 14, 2024 12:52
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
max-parallel: 2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bit of a bottleneck, and I think we should be able to run more tests in parallel.

var pgErr *pgconn.PgError
ok := errors.As(err, &pgErr)
check.Bool(t, ok, true)
check.Equal(t, pgErr.Code, "42P07") // duplicate_table
Copy link
Collaborator Author

@mfridman mfridman Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire dialect store can be tested with SQLite. The only reason we had postgres in here was to test for this duplicate table error, confirming the error can be correctly asserted from caller -> driver -> goose -> caller.

@@ -0,0 +1,87 @@
module github.com/pressly/goose/v3/internal/testing

go 1.22.1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables us to keep up-to-date with drivers without having to fight them on the minimum supported Go version.

This will especially be useful if we go down this route with #664

)

func TestGoMigrationByOne(t *testing.T) {
db, cleanup, err := testdb.NewPostgres()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can test go migrations with SQLite, there is nothing inherently special about using postgres in these tests, since we're asserting for the correct goose library behaviour handling go migrations.

@mfridman mfridman merged commit b2c483a into master Mar 14, 2024
5 checks passed
@mfridman mfridman deleted the gh711 branch March 14, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant