Skip to content

Commit

Permalink
Create unit test pipeline
Browse files Browse the repository at this point in the history
- Add go.yml to start build and test jobs.
- Fix minor issues in the code.

Signed-off-by: Diogo Behrens <[email protected]>
  • Loading branch information
db7 committed Mar 27, 2024
1 parent e12014a commit 0f41ced
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/build_vsyncer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ lint:
revive -exclude vendor/... ./...

test:
go test -cover ./...
go test -v ./...

cover:
go test -coverpkg=./... -coverprofile=cover.out ./...
Expand Down
5 changes: 3 additions & 2 deletions cmd/vsyncer/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/vsyncer/csvreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0f41ced

Please sign in to comment.