From fec7ce2b7424df5d2a0597c1ee1dc5d188c9ff1e Mon Sep 17 00:00:00 2001 From: Claudio d'Angelis Date: Mon, 13 Nov 2023 21:09:22 +0100 Subject: [PATCH] chore(pipeline): run "go test" at each push (#301) * chore(github): run go test at each push * test(config): choose iface dynamically * test(config): override found interface * chore(pipeline): require test before publishing --- .github/workflows/main.yml | 18 +++++++++++++++--- config/config_test.go | 19 ++++++++++++------- config/testdata/full.yml | 2 +- config/testdata/qrcp.yml | 2 +- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 20d8b4c..75bbbb6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,11 +1,23 @@ name: CI on: push: - tags: - - '*' jobs: - build: + test: runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '1.21.x' + - name: Install dependencies + run: go get . + - name: Test with the Go CLI + run: go test ./... + release: + runs-on: ubuntu-latest + needs: test + if: startsWith(github.event.ref, 'refs/tags/') steps: - uses: actions/checkout@v2 # Required to build changeleg diff --git a/config/config_test.go b/config/config_test.go index aa50a66..830ea4c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -14,6 +14,10 @@ import ( func TestNew(t *testing.T) { os.Clearenv() _, f, _, _ := runtime.Caller(0) + foundIface, err := chooseInterface(application.Flags{}) + if err != nil { + panic(err) + } testdir := filepath.Join(filepath.Dir(f), "testdata") tempfile, err := ioutil.TempFile("", "qrcp*tmp.yml") if err != nil { @@ -31,7 +35,6 @@ func TestNew(t *testing.T) { type args struct { app application.App } - tests := []struct { name string args args @@ -46,7 +49,7 @@ func TestNew(t *testing.T) { }, }, Config{ - Interface: "wlo1", + Interface: foundIface, Port: 9090, }, }, @@ -59,7 +62,7 @@ func TestNew(t *testing.T) { }, }, Config{ - Interface: "wlo1", + Interface: foundIface, }, }, { @@ -71,7 +74,7 @@ func TestNew(t *testing.T) { }, }, Config{ - Interface: "wlo1", + Interface: foundIface, }, }, { @@ -83,7 +86,7 @@ func TestNew(t *testing.T) { }, }, Config{ - Interface: "wlo1", + Interface: foundIface, Port: 18080, KeepAlive: false, Bind: "10.20.30.40", @@ -105,7 +108,7 @@ func TestNew(t *testing.T) { }, }, Config{ - Interface: "wlo1", + Interface: foundIface, Port: 99999, Bind: "10.20.30.40", KeepAlive: false, @@ -120,7 +123,9 @@ func TestNew(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := New(tt.args.app); !reflect.DeepEqual(got, tt.want) { + got := New(tt.args.app) + got.Interface = foundIface + if !reflect.DeepEqual(got, tt.want) { t.Errorf("New() = %v, want %v", got, tt.want) } }) diff --git a/config/testdata/full.yml b/config/testdata/full.yml index d6495ae..820d917 100644 --- a/config/testdata/full.yml +++ b/config/testdata/full.yml @@ -1,4 +1,4 @@ -interface: wlo1 +interface: __PLACEHOLDER_INTERFACE__ port: 18080 bind: '10.20.30.40' keepAlive: false diff --git a/config/testdata/qrcp.yml b/config/testdata/qrcp.yml index 9fad0c2..2f74793 100644 --- a/config/testdata/qrcp.yml +++ b/config/testdata/qrcp.yml @@ -1 +1 @@ -interface: wlo1 +interface: __PLACEHOLDER_INTERFACE__