Skip to content

Commit

Permalink
Fix tests by providing a PostgreSQL database container (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfrench authored Oct 28, 2021
1 parent 7217c24 commit 9ca5251
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ jobs:
with:
mongodb-version: 4.2

- name: Start PostgreSQL 14
uses: harmon758/postgresql-action@v1
with:
postgresql db: testdb
postgresql user: testuser
postgresql password: testpw
postgresql version: '14'

- uses: niden/actions-memcached@v7

- name: Set up Go ${{ matrix.go }}
Expand Down
10 changes: 2 additions & 8 deletions postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ import (
"database/sql"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/tester"
"os"
"testing"
)

const postgresTestServer = "postgres://testuser:testpw@localhost:5432/testdb?sslmode=disable"

var newStore = func(_ *testing.T) sessions.Store {
// Env var in the format postgresql://username:password@localhost:5432/database?sslmode=disable required
dsn := os.Getenv("SESSIONS_POSTGRES_TEST")
if dsn == "" {
panic("database connection is required")
}

db, err := sql.Open("postgres", dsn)
db, err := sql.Open("postgres", postgresTestServer)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 9ca5251

Please sign in to comment.