From 0f41cedbf98d9c8476639b79aa77e36f465fb224 Mon Sep 17 00:00:00 2001 From: Diogo Behrens Date: Thu, 29 Feb 2024 12:51:14 +0100 Subject: [PATCH] Create unit test pipeline - Add go.yml to start build and test jobs. - Fix minor issues in the code. Signed-off-by: Diogo Behrens --- .github/workflows/build_vsyncer.yml | 8 ++------ .github/workflows/go.yml | 25 +++++++++++++++++++++++++ Makefile | 2 +- cmd/vsyncer/check_test.go | 5 +++-- cmd/vsyncer/csvreport.go | 2 +- 5 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/build_vsyncer.yml b/.github/workflows/build_vsyncer.yml index 0d5e36f..d6990b9 100644 --- a/.github/workflows/build_vsyncer.yml +++ b/.github/workflows/build_vsyncer.yml @@ -19,17 +19,13 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - # list of Docker images to use as base name for tags images: | ghcr.io/open-s4c/vsyncer tags: | - type=schedule type=ref,event=branch + type=ref,event=tag type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha + type=edge,branch=main - name: Log in to the Container registry # TODO: if: github.event_name != 'pull_request' uses: docker/login-action@v3.0.0 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..995389b --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,25 @@ +name: Go + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Build + run: make all + + - name: Test + run: make test diff --git a/Makefile b/Makefile index 1e34cbc..afb53c3 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ lint: revive -exclude vendor/... ./... test: - go test -cover ./... + go test -v ./... cover: go test -coverpkg=./... -coverprofile=cover.out ./... diff --git a/cmd/vsyncer/check_test.go b/cmd/vsyncer/check_test.go index 59d62c8..6b47202 100644 --- a/cmd/vsyncer/check_test.go +++ b/cmd/vsyncer/check_test.go @@ -79,14 +79,15 @@ func TestCheck(t *testing.T) { orderSelection = nil err := checkRun(nil, args) - if tc.err == nil { + if tc.r.Status == checker.CheckOK && tc.err == nil { assert.Nil(t, err) return } else if terr, tok := tc.err.(*vError); tok { assert.NotNil(t, err) er, ok := err.(*vError) assert.True(t, ok) - assert.Equal(t, er.typ, terr.typ) + assert.Equal(t, terr.typ, er.typ) + assert.Equal(t, tc.r.Status, er.status) return } assert.NotNil(t, err) diff --git a/cmd/vsyncer/csvreport.go b/cmd/vsyncer/csvreport.go index c08605f..5fcc27c 100644 --- a/cmd/vsyncer/csvreport.go +++ b/cmd/vsyncer/csvreport.go @@ -55,7 +55,7 @@ func (csv csvReport) save(filename string) { fmt.Fprintln(fp) } - fmt.Fprintf(fp, "%s, %s, %s, %v, %v, %v, %v, %d, %s, %d\n", + fmt.Fprintf(fp, "%s, %s, %v, %v, %v, %v, %v, %d, %s, %d\n", time.Now().Format(dateTime), csv.name, csv.checker,