From 8fe0bf614a46a6f9eef96ef66eeec17640cc3071 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 14 Oct 2020 22:42:42 +0900 Subject: [PATCH] test: add examples of buildflow configuration and tests of them --- .github/workflows/test.yml | 3 +++ ci/test-example.sh | 11 +++++++++++ examples/go.mod | 5 +++++ examples/go.sum | 16 ++++++++++++++++ examples/hello_world.yaml | 7 +++++++ examples/main_test.go | 23 +++++++++++++++++++++++ examples/parallel.yaml | 12 ++++++++++++ 7 files changed, 77 insertions(+) create mode 100644 ci/test-example.sh create mode 100644 examples/go.mod create mode 100644 examples/go.sum create mode 100755 examples/hello_world.yaml create mode 100644 examples/main_test.go create mode 100644 examples/parallel.yaml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4781919..f5c6310 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,9 @@ jobs: CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} run: | bash ci/test.sh buildflow + - name: test examples + run: | + bash ci/test-example.sh - name: remove changes # Sometimes it is failed to release by goreleaser due to changes of go.sum diff --git a/ci/test-example.sh b/ci/test-example.sh new file mode 100644 index 0000000..b0243cd --- /dev/null +++ b/ci/test-example.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -eu + +cd "$(dirname "$0")/.." + +go build -o dist/buildflow ./cmd/buildflow +export PATH="$PWD/dist:$PATH" +cd examples +go test -race -covermode=atomic ./... +rm -R ../dist diff --git a/examples/go.mod b/examples/go.mod new file mode 100644 index 0000000..f010f78 --- /dev/null +++ b/examples/go.mod @@ -0,0 +1,5 @@ +module examples + +go 1.15 + +require gotest.tools/v3 v3.0.3 diff --git a/examples/go.sum b/examples/go.sum new file mode 100644 index 0000000..4ab15d6 --- /dev/null +++ b/examples/go.sum @@ -0,0 +1,16 @@ +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gotest.tools v1.4.0 h1:BjtEgfuw8Qyd+jPvQz8CfoxiO/UjFEidWinwEXZiWv0= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= +gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= +gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= diff --git a/examples/hello_world.yaml b/examples/hello_world.yaml new file mode 100755 index 0000000..41542e1 --- /dev/null +++ b/examples/hello_world.yaml @@ -0,0 +1,7 @@ +--- +phases: +- name: main + tasks: + - name: hello + command: + command: echo hello diff --git a/examples/main_test.go b/examples/main_test.go new file mode 100644 index 0000000..1fca0d3 --- /dev/null +++ b/examples/main_test.go @@ -0,0 +1,23 @@ +package examples_test + +import ( + "testing" + + "gotest.tools/v3/icmd" +) + +func TestHelloWorld(t *testing.T) { + result := icmd.RunCmd(icmd.Command("buildflow", "run", "-c", "hello_world.yaml")) + result.Assert(t, icmd.Expected{ + ExitCode: 0, + Err: "", + }) +} + +func TestParallel(t *testing.T) { + result := icmd.RunCmd(icmd.Command("buildflow", "run", "-c", "parallel.yaml")) + result.Assert(t, icmd.Expected{ + ExitCode: 0, + Err: "", + }) +} diff --git a/examples/parallel.yaml b/examples/parallel.yaml new file mode 100644 index 0000000..c230909 --- /dev/null +++ b/examples/parallel.yaml @@ -0,0 +1,12 @@ +--- +phases: +- name: main + tasks: + - name: foo + command: + command: | + echo foo + - name: bar + command: + command: | + echo bar