Skip to content

Commit 06a897c

Browse files
committed
chore: setup integration test
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
1 parent 807213a commit 06a897c

File tree

7 files changed

+103
-0
lines changed

7 files changed

+103
-0
lines changed

.github/workflows/go.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,28 @@ jobs:
171171
env_vars: OS,GOLANG
172172
name: codecov-umbrella
173173
fail_ci_if_error: false
174+
integration-tests:
175+
runs-on: ubuntu-latest
176+
strategy:
177+
matrix:
178+
golang:
179+
- 1.15.1
180+
env:
181+
OS: ubuntu-latest
182+
GOLANG: ${{ matrix.golang }}
183+
steps:
184+
- uses: actions/checkout@v2
185+
- name: Install Go
186+
uses: actions/setup-go@v2
187+
with:
188+
go-version: ${{ matrix.golang }}
189+
- uses: actions/cache@v1
190+
with:
191+
path: ~/go/pkg/mod
192+
key: ${{ runner.os }}-go-${{ matrix.golang }}-${{ hashFiles('**/go.sum') }}
193+
restore-keys: |
194+
${{ runner.os }}-go-${{ matrix.golang }}-
195+
- name: Compile the project
196+
run: make go.install
197+
- name: Run integration tests
198+
run: make integration

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ GOBINS ?= .
44
NPM_PACKAGES ?= .
55

66
include rules.mk
7+
8+
integration: install
9+
cd examples && make integration

examples/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
integration:
2+
# test with testman
3+
testman test -run ^TestStable ./...
4+
@# FIXME: test unstable tests
5+
@# FIXME: test broken tests
6+
7+
# test with default tools
8+
go install moul.io/retry
9+
go test -run ^TestStable -count=20 ./... >/dev/null # should always work
10+
retry -m=5 --interval=0 -- "(go test -run ^TestBroken -count=1 ./... >/dev/null)" && exit 1 || exit 0 # should always fail
11+
retry -m=50 --interval=0 -- "(go test -run ^TestUnstable -count 1 ./... >/dev/null)" # should work at least 1/50
12+
go mod tidy
13+
14+
@echo "SUCCESS."

examples/go.mod

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/testpkg/testpkg.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package testpkg
2+
3+
import (
4+
"fmt"
5+
"math/rand"
6+
)
7+
8+
func AlwaysSucceed() error {
9+
return nil
10+
}
11+
12+
func AlwaysFailing() error {
13+
return fmt.Errorf("hope is the key to life")
14+
}
15+
16+
func MaySucceed() error {
17+
if rand.Intn(3) != 0 {
18+
return fmt.Errorf("oops, no luck, try again")
19+
}
20+
return nil
21+
}

examples/testpkg/testpkg_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package testpkg
2+
3+
import (
4+
"fmt"
5+
"math/rand"
6+
"testing"
7+
8+
"moul.io/srand"
9+
)
10+
11+
func ExampleAlwaysSucceed() {
12+
fmt.Println(AlwaysSucceed())
13+
// Output: <nil>
14+
}
15+
16+
func TestStableAlwaysSucceed(t *testing.T) {
17+
if err := AlwaysSucceed(); err != nil {
18+
t.Errorf("expect no error, got %v", err)
19+
}
20+
}
21+
22+
func TestUnstableMaySucceed(t *testing.T) {
23+
rand.Seed(srand.Fast())
24+
if err := MaySucceed(); err != nil {
25+
t.Errorf("expect no error, got %v", err)
26+
}
27+
}
28+
29+
func TestBrokenAlwaysFailing(t *testing.T) {
30+
if err := AlwaysFailing(); err != nil {
31+
t.Errorf("expect no error, got %v", err)
32+
}
33+
}

0 commit comments

Comments
 (0)