From 06a897cba7a94af8295bb96a09b6000cf5765b7f Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Sun, 6 Sep 2020 21:21:29 +0200 Subject: [PATCH] chore: setup integration test Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com> --- .github/workflows/go.yml | 25 ++++++++++++++++++++++++ Makefile | 3 +++ examples/Makefile | 14 ++++++++++++++ examples/go.mod | 5 +++++ examples/go.sum | 2 ++ examples/testpkg/testpkg.go | 21 ++++++++++++++++++++ examples/testpkg/testpkg_test.go | 33 ++++++++++++++++++++++++++++++++ 7 files changed, 103 insertions(+) create mode 100644 examples/Makefile create mode 100644 examples/go.mod create mode 100644 examples/go.sum create mode 100644 examples/testpkg/testpkg.go create mode 100644 examples/testpkg/testpkg_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f96e158..1b90a83 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -171,3 +171,28 @@ jobs: env_vars: OS,GOLANG name: codecov-umbrella fail_ci_if_error: false + integration-tests: + runs-on: ubuntu-latest + strategy: + matrix: + golang: + - 1.15.1 + env: + OS: ubuntu-latest + GOLANG: ${{ matrix.golang }} + steps: + - uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.golang }} + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ matrix.golang }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ matrix.golang }}- + - name: Compile the project + run: make go.install + - name: Run integration tests + run: make integration diff --git a/Makefile b/Makefile index 0930f7b..006cd15 100644 --- a/Makefile +++ b/Makefile @@ -4,3 +4,6 @@ GOBINS ?= . NPM_PACKAGES ?= . include rules.mk + +integration: install + cd examples && make integration diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..b660ec9 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,14 @@ +integration: + # test with testman + testman test -run ^TestStable ./... + @# FIXME: test unstable tests + @# FIXME: test broken tests + + # test with default tools + go install moul.io/retry + go test -run ^TestStable -count=20 ./... >/dev/null # should always work + retry -m=5 --interval=0 -- "(go test -run ^TestBroken -count=1 ./... >/dev/null)" && exit 1 || exit 0 # should always fail + retry -m=50 --interval=0 -- "(go test -run ^TestUnstable -count 1 ./... >/dev/null)" # should work at least 1/50 + go mod tidy + + @echo "SUCCESS." diff --git a/examples/go.mod b/examples/go.mod new file mode 100644 index 0000000..786d248 --- /dev/null +++ b/examples/go.mod @@ -0,0 +1,5 @@ +module moul.io/testman/examples + +go 1.15 + +require moul.io/srand v1.5.0 diff --git a/examples/go.sum b/examples/go.sum new file mode 100644 index 0000000..1b4d0b5 --- /dev/null +++ b/examples/go.sum @@ -0,0 +1,2 @@ +moul.io/srand v1.5.0 h1:xGelp9uiK52NClaWCvQWHvVAXzhVrWDA5NiwnGp2JkU= +moul.io/srand v1.5.0/go.mod h1:P2uaZB+GFstFNo8sEj6/U8FRV1n25kD0LLckFpJ+qvc= diff --git a/examples/testpkg/testpkg.go b/examples/testpkg/testpkg.go new file mode 100644 index 0000000..3ab2a41 --- /dev/null +++ b/examples/testpkg/testpkg.go @@ -0,0 +1,21 @@ +package testpkg + +import ( + "fmt" + "math/rand" +) + +func AlwaysSucceed() error { + return nil +} + +func AlwaysFailing() error { + return fmt.Errorf("hope is the key to life") +} + +func MaySucceed() error { + if rand.Intn(3) != 0 { + return fmt.Errorf("oops, no luck, try again") + } + return nil +} diff --git a/examples/testpkg/testpkg_test.go b/examples/testpkg/testpkg_test.go new file mode 100644 index 0000000..9d4fd13 --- /dev/null +++ b/examples/testpkg/testpkg_test.go @@ -0,0 +1,33 @@ +package testpkg + +import ( + "fmt" + "math/rand" + "testing" + + "moul.io/srand" +) + +func ExampleAlwaysSucceed() { + fmt.Println(AlwaysSucceed()) + // Output: +} + +func TestStableAlwaysSucceed(t *testing.T) { + if err := AlwaysSucceed(); err != nil { + t.Errorf("expect no error, got %v", err) + } +} + +func TestUnstableMaySucceed(t *testing.T) { + rand.Seed(srand.Fast()) + if err := MaySucceed(); err != nil { + t.Errorf("expect no error, got %v", err) + } +} + +func TestBrokenAlwaysFailing(t *testing.T) { + if err := AlwaysFailing(); err != nil { + t.Errorf("expect no error, got %v", err) + } +}