From ef209011a889d3c30859795ff115abd202e84d4d Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Thu, 1 Dec 2022 15:28:39 +0100 Subject: [PATCH] Add something about setting up Postgres to run tests --- docs/CONTRIBUTING.md | 15 ++++++++++++++- test/db.go | 5 +---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 6ba05f46f..262a93a7c 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -75,7 +75,20 @@ comment. Please avoid doing this if you can. We also have unit tests which we run via: ```bash -go test --race ./... +DENDRITE_TEST_SKIP_NODB=1 go test --race ./... +``` + +This only runs SQLite database tests. If you wish to execute Postgres tests as well, you'll either need to +have Postgres installed locally (`createdb` will be used) or have a remote/containerized Postgres instance +available. + +To configure the connection to a remote Postgres, you can use the following enviroment variables: + +```bash +POSTGRES_USER=postgres +POSTGERS_PASSWORD=yourPostgresPassword +POSTGRES_HOST=localhost +POSTGRES_DB=postgres # the superuser database to use ``` In general, we like submissions that come with tests. Anything that proves that the diff --git a/test/db.go b/test/db.go index 4c95e307f..8afdb3c19 100644 --- a/test/db.go +++ b/test/db.go @@ -65,10 +65,7 @@ func createRemoteDB(t *testing.T, dbName, user, connStr string) { fatalError(t, "failed to open postgres conn with connstr=%s : %s", connStr, err) } if err = db.Ping(); err != nil { - // If we're unable to reach the database, it's unlikely that a postgres server is - // available for testing. Set Required to false to skip the test instead of failing it. - Required = false - t.Logf("Note: tests require a postgres install accessible to the current user") + fatalError(t, "failed to open postgres conn with connstr=%s : %s", connStr, err) } _, err = db.Exec(fmt.Sprintf(`CREATE DATABASE %s;`, dbName))