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

Bootstrap GitHub actions workflow #205

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
test:
runs-on: ubuntu-latest

services:

mysql:
image: mysql
env:
MYSQL_ROOT_PASSWORD: root-password
MYSQL_DATABASE: dbname
MYSQL_USER: user
MYSQL_PASSWORD: password
options: >-
--health-cmd "mysqladmin ping --silent"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 3306:3306

postgres:
image: postgres
env:
POSTGRES_DB: dbname
POSTGRES_USER: user
POSTGRES_PASSWORD: password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'

- name: Test
run: go test -race -v ./...

- name: Run postgres migrations
run: psql -f pgxstore/testdata/schema.sql postgres://user:password@localhost:5432/dbname

- name: Run mysql migrations
run: mysql --protocol=TCP --host=localhost --port=3306 --user=user --password=password dbname < mysqlstore/testdata/schema.sql

- name: Test goredisstore
env:
SCS_REDIS_TEST_DSN: redis://localhost:6379
working-directory: goredisstore
run: go test -race -v ./...

- name: Test mysqlstore
env:
SCS_MYSQL_TEST_DSN: user:password@tcp(localhost:3306)/dbname
working-directory: mysqlstore
run: go test -race -v ./...

- name: Test pgxstore
env:
SCS_POSTGRES_TEST_DSN: postgres://user:password@localhost:5432/dbname
working-directory: pgxstore
run: go test -race -v ./...

- name: Test postgresstore
env:
SCS_POSTGRES_TEST_DSN: postgres://user:password@localhost:5432/dbname?sslmode=disable
working-directory: postgresstore
run: go test -race -v ./...

- name: Test redisstore
env:
SCS_REDIS_TEST_DSN: localhost:6379
working-directory: redisstore
run: go test -race -v ./...

- name: Test sqlite3store
working-directory: sqlite3store
run: go test -race -v ./...
6 changes: 6 additions & 0 deletions memstore/memstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,21 @@ func TestDelete(t *testing.T) {
func TestCleanupInterval(t *testing.T) {
m := NewWithCleanupInterval(100 * time.Millisecond)
defer m.StopCleanup()
m.mu.Lock()
m.items["session_token"] = item{object: []byte("encoded_data"), expiration: time.Now().Add(500 * time.Millisecond).UnixNano()}
m.mu.Unlock()

m.mu.Lock()
_, ok := m.items["session_token"]
m.mu.Unlock()
if !ok {
t.Fatalf("got %v: expected %v", ok, true)
}

time.Sleep(time.Second)
m.mu.Lock()
_, ok = m.items["session_token"]
m.mu.Unlock()
if ok {
t.Fatalf("got %v: expected %v", ok, false)
}
Expand Down
7 changes: 7 additions & 0 deletions mysqlstore/testdata/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE sessions (
token CHAR(43) PRIMARY KEY,
data BLOB NOT NULL,
expiry TIMESTAMP(6) NOT NULL
);

CREATE INDEX sessions_expiry_idx ON sessions (expiry);
7 changes: 7 additions & 0 deletions pgxstore/testdata/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE sessions (
token TEXT PRIMARY KEY,
data BYTEA NOT NULL,
expiry TIMESTAMPTZ NOT NULL
);

CREATE INDEX sessions_expiry_idx ON sessions (expiry);