Skip to content

Commit 9ca5251

Browse files
authored
Fix tests by providing a PostgreSQL database container (#141)
1 parent 7217c24 commit 9ca5251

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

.github/workflows/testing.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ jobs:
2121
with:
2222
mongodb-version: 4.2
2323

24+
- name: Start PostgreSQL 14
25+
uses: harmon758/postgresql-action@v1
26+
with:
27+
postgresql db: testdb
28+
postgresql user: testuser
29+
postgresql password: testpw
30+
postgresql version: '14'
31+
2432
- uses: niden/actions-memcached@v7
2533

2634
- name: Set up Go ${{ matrix.go }}

postgres/postgres_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ import (
44
"database/sql"
55
"github.com/gin-contrib/sessions"
66
"github.com/gin-contrib/sessions/tester"
7-
"os"
87
"testing"
98
)
109

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

1212
var newStore = func(_ *testing.T) sessions.Store {
13-
// Env var in the format postgresql://username:password@localhost:5432/database?sslmode=disable required
14-
dsn := os.Getenv("SESSIONS_POSTGRES_TEST")
15-
if dsn == "" {
16-
panic("database connection is required")
17-
}
18-
19-
db, err := sql.Open("postgres", dsn)
13+
db, err := sql.Open("postgres", postgresTestServer)
2014
if err != nil {
2115
panic(err)
2216
}

0 commit comments

Comments
 (0)