Add something about setting up Postgres to run tests

This commit is contained in:
Till Faelligen 2022-12-01 15:28:39 +01:00
parent 3121a9f17b
commit ef209011a8
No known key found for this signature in database
GPG key ID: ACCDC9606D472758
2 changed files with 15 additions and 5 deletions

View file

@ -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

View file

@ -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))