Skip to content

Commit 21a4e3b

Browse files
authored
Update docker configuration to run all tests in a container. Updated … (#70)
Update docker configuration to run all tests in a container. Updated CI workflow to use the latest go action.
1 parent c1e5708 commit 21a4e3b

8 files changed

Lines changed: 57 additions & 29 deletions

File tree

.github/workflows/go.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will build a golang project
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
33

4-
name: go-querysql-test
4+
name: sqlcode
55

66
on:
77
pull_request:
@@ -11,19 +11,16 @@ jobs:
1111

1212
build:
1313
runs-on: ubuntu-latest
14-
env:
15-
SQLSERVER_DSN: "sqlserver://127.0.0.1:1433?database=master&user id=sa&password=VippsPw1"
14+
strategy:
15+
matrix:
16+
driver: ['mssql']
1617
steps:
17-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v5
1819

1920
- name: Set up Go
2021
uses: actions/setup-go@v5
2122
with:
22-
go-version: '1.23'
23-
24-
- name: Start db
25-
run: docker compose -f docker-compose.test.yml up -d
23+
go-version: '1.25'
2624

2725
- name: Test
28-
# Skip the example folder because it has examples of what-not-to-do
29-
run: go test -v $(go list ./... | grep -v './example')
26+
run: docker compose -f docker-compose.${{ matrix.driver }}.yml run test

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test: test-mssql
2+
3+
.PHONY:
4+
test-mssql:
5+
docker compose --progress plain -f docker-compose.mssql.yml run test

docker-compose.mssql.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
services:
2+
mssql:
3+
image: mcr.microsoft.com/mssql/server:latest
4+
networks:
5+
- mssql
6+
environment:
7+
ACCEPT_EULA: "Y"
8+
SA_PASSWORD: VippsPw1
9+
healthcheck:
10+
test: ["CMD", "/opt/mssql-tools18/bin/sqlcmd", "-C", "-Usa", "-PVippsPw1", "-Q", "select 1"]
11+
interval: 1s
12+
retries: 20
13+
test:
14+
build:
15+
no_cache: true
16+
context: .
17+
dockerfile: dockerfile.test
18+
networks:
19+
- mssql
20+
volumes:
21+
- $PWD:/sqlcode
22+
environment:
23+
SQLSERVER_DSN: sqlserver://mssql:1433?database=master&user id=sa&password=VippsPw1
24+
GODEBUG: "x509negativeserial=1"
25+
depends_on:
26+
mssql:
27+
condition: service_healthy
28+
networks:
29+
mssql:

docker-compose.test.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

dockerfile.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM golang:1.25 AS builder
2+
WORKDIR /sqlcode
3+
COPY . .
4+
RUN go mod tidy
5+
CMD ["go", "test", "-v", "-cover", "./..."]

example/basic/example.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build examples
2+
// +build examples
3+
14
package example
25

36
import (

example/basic/example_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
//go:build examples
2+
// +build examples
3+
14
package example
25

36
import (
47
"context"
58
"fmt"
9+
"testing"
10+
"time"
11+
612
"github.com/stretchr/testify/assert"
713
"github.com/stretchr/testify/require"
814
"github.com/vippsas/sqlcode/sqltest"
9-
"testing"
10-
"time"
1115
)
1216

1317
func TestPreprocess(t *testing.T) {

sqlcode.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
databases:
2-
localtest:
3-
connection: sqlserver://localhost:1433?database=foo&user id=foouser&password=FooPasswd1
2+
mssql:
3+
connection: sqlserver://mssql:1433?database=foo&user id=foouser&password=FooPasswd1
44

55
# One option is to list other paths to include ('dependencies') here.
66

0 commit comments

Comments
 (0)