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

Add testing.M / TestMain support that ensures a DB connection can be made #14

Open
dhermes opened this issue Aug 21, 2020 · 1 comment
Assignees

Comments

@dhermes
Copy link
Owner

dhermes commented Aug 21, 2020

It may be nice to utilize https://github.com/ory/dockertest as well, but this seems very heavyweight.

@dhermes dhermes self-assigned this Aug 21, 2020
@dhermes
Copy link
Owner Author

dhermes commented Aug 21, 2020

A common pattern with https://godoc.org/github.com/blend/go-sdk/db is to do

func TestMain(m *testing.M) {
	conn, err := db.New(db.OptConfigFromEnv())
	if err != nil {
		log.Fatalf("%+v", err)
	}
	err = OpenDefaultDB(conn)
	if err != nil {
		log.Fatalf("%+v", err)
	}
	assert.Main(m)
}

so it may be worth one (or both) of

  • supporting mapping environment variables to a postgres.Config object (e.g. via a hard-coded path helper or via a struct tag)
  • adopting go-sdk/db helpers here (I was trying to avoid having dependencies outside of the standard library; even driver dependencies are not included)

Subscript, see current dependencies:

$ git log -1 --pretty=%H
1f7dffc658eb39b0c473c107bafeaac66168d9e8
$ go list -f '{{ .ImportPath }} | {{ .Imports }}' ./...
github.com/dhermes/golembic | [context database/sql errors fmt io/ioutil sync time]
github.com/dhermes/golembic/command | [context errors fmt github.com/dhermes/golembic github.com/dhermes/golembic/postgres github.com/spf13/cobra github.com/spf13/pflag os strings time]
github.com/dhermes/golembic/examples | [github.com/dhermes/golembic path/filepath]
github.com/dhermes/golembic/examples/cmd | [github.com/dhermes/golembic/command github.com/dhermes/golembic/examples github.com/lib/pq log]
github.com/dhermes/golembic/examples/script | [context github.com/dhermes/golembic github.com/dhermes/golembic/examples github.com/dhermes/golembic/postgres github.com/lib/pq log os]
github.com/dhermes/golembic/postgres | [database/sql errors fmt github.com/dhermes/golembic net/url strings time]

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

No branches or pull requests

1 participant