Skip to content

Commit d92eb9c

Browse files
authored
Add Unit/Integration testing jobs to CI pipeline (#13)
1 parent 4f579b5 commit d92eb9c

4 files changed

Lines changed: 96 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: LSTK CI
22

33
on:
44
push:
@@ -9,6 +9,8 @@ on:
99

1010
permissions:
1111
contents: read
12+
pull-requests: write
13+
checks: write
1214

1315
jobs:
1416
lint:
@@ -27,3 +29,76 @@ jobs:
2729
uses: golangci/golangci-lint-action@v9
2830
with:
2931
version-file: .tool-versions
32+
33+
test-unit:
34+
name: Unit Tests
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v6
39+
40+
- name: Set up Go
41+
uses: actions/setup-go@v6
42+
with:
43+
go-version-file: go.mod
44+
cache-dependency-path: go.sum
45+
46+
- name: Run unit tests
47+
run: make test
48+
env:
49+
CREATE_JUNIT_REPORT: "true"
50+
51+
- name: Upload test results
52+
uses: actions/upload-artifact@v4
53+
if: always()
54+
with:
55+
name: unit-test-results
56+
path: test-results.xml
57+
58+
- name: Test report
59+
uses: dorny/test-reporter@v1
60+
if: always()
61+
with:
62+
name: Unit Test Results
63+
path: test-results.xml
64+
reporter: java-junit
65+
66+
test-integration:
67+
name: Integration Tests (${{ matrix.os }})
68+
runs-on: ${{ matrix.os }}
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
os: [ubuntu-latest, macos-latest, windows-latest]
73+
steps:
74+
- name: Checkout code
75+
uses: actions/checkout@v6
76+
77+
- name: Set up Go
78+
uses: actions/setup-go@v6
79+
with:
80+
go-version-file: go.mod
81+
cache-dependency-path: |
82+
go.sum
83+
test/integration/go.sum
84+
85+
- name: Run integration tests
86+
run: make test-integration
87+
env:
88+
CREATE_JUNIT_REPORT: "true"
89+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
90+
91+
- name: Upload test results
92+
uses: actions/upload-artifact@v4
93+
if: always()
94+
with:
95+
name: integration-test-results-${{ matrix.os }}
96+
path: test-integration-results.xml
97+
98+
- name: Test report
99+
uses: dorny/test-reporter@v1
100+
if: always()
101+
with:
102+
name: Integration Test Results (${{ matrix.os }})
103+
path: test-integration-results.xml
104+
reporter: java-junit

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ clean:
1010
rm -rf $(BUILD_DIR)
1111

1212
test:
13-
go test ./internal/...
13+
@JUNIT=""; [ -n "$$CREATE_JUNIT_REPORT" ] && JUNIT="--junitfile test-results.xml"; \
14+
go run gotest.tools/gotestsum@latest --format testdox $$JUNIT -- ./cmd/... ./internal/...
1415

1516
test-integration: build
16-
cd test/integration && go test -count=1 -v .
17+
@JUNIT=""; [ -n "$$CREATE_JUNIT_REPORT" ] && JUNIT="--junitfile ../../test-integration-results.xml"; \
18+
cd test/integration && go run gotest.tools/gotestsum@latest --format testdox $$JUNIT -- -count=1 ./...
1719

1820
mock-generate:
1921
go generate ./...

test/integration/main_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
package integration_test
22

33
import (
4+
"context"
45
"testing"
56

67
"github.com/docker/docker/client"
78
)
89

910
var dockerClient *client.Client
11+
var dockerAvailable bool
1012

1113
func TestMain(m *testing.M) {
1214
var err error
1315
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
14-
if err != nil {
15-
panic(err)
16+
if err == nil {
17+
_, err = dockerClient.Ping(context.Background())
18+
dockerAvailable = err == nil
1619
}
1720
m.Run()
1821
}
22+
23+
func requireDocker(t *testing.T) {
24+
t.Helper()
25+
if !dockerAvailable {
26+
t.Skip("Docker is not available")
27+
}
28+
}

test/integration/start_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
const containerName = "localstack-aws"
2323

2424
func TestStartCommandSucceedsWithValidToken(t *testing.T) {
25+
requireDocker(t)
2526
authToken := os.Getenv("LOCALSTACK_AUTH_TOKEN")
2627
require.NotEmpty(t, authToken, "LOCALSTACK_AUTH_TOKEN must be set to run this test")
2728

@@ -43,6 +44,7 @@ func TestStartCommandSucceedsWithValidToken(t *testing.T) {
4344
}
4445

4546
func TestStartCommandTriggersLoginWithoutToken(t *testing.T) {
47+
requireDocker(t)
4648
cleanup()
4749
t.Cleanup(cleanup)
4850

@@ -80,6 +82,7 @@ func TestStartCommandTriggersLoginWithoutToken(t *testing.T) {
8082
}
8183

8284
func TestStartCommandSucceedsWithKeyringToken(t *testing.T) {
85+
requireDocker(t)
8386
cleanup()
8487
t.Cleanup(cleanup)
8588

@@ -105,6 +108,7 @@ func TestStartCommandSucceedsWithKeyringToken(t *testing.T) {
105108
}
106109

107110
func TestStartCommandFailsWithInvalidToken(t *testing.T) {
111+
requireDocker(t)
108112
cleanup()
109113
t.Cleanup(cleanup)
110114

0 commit comments

Comments
 (0)