From cb74b278f0dbee64798892fa4a263cccf962dc9a Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Thu, 14 Mar 2024 15:34:02 -0400 Subject: [PATCH 1/2] Add github actions We have tests just not in gh actions --- .github/workflows/test.yaml | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..77aa36e --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,44 @@ +name: CI +on: + push: + branches: + - main + pull_request: + branches: + - main +env: + GOPATH: /home/runner/go/ + GOPROXY: "https://proxy.golang.org" +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version-file: go.mod + check-latest: true + - run: PATH=$PATH:$GOPATH/bin make build + test: + name: Unit test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version-file: go.mod + check-latest: true + - run: PATH=$PATH:$GOPATH/bin make test + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version-file: go.mod + check-latest: true + - uses: golangci/golangci-lint-action@v3 + with: + version: latest From 9ce724ae39a34d123d1dbb6f9047b91404bd4d5c Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Thu, 14 Mar 2024 15:41:02 -0400 Subject: [PATCH 2/2] fix lint issues --- Makefile | 3 +++ algorithms/graph_test.go | 4 ++-- containers/set.go | 12 ++++++------ containers/stack_test.go | 4 ++-- retry/algorithms.go | 6 +----- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index fa8150a..5e969cb 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,9 @@ build: .PHONY # compiles test: .PHONY # tests the codebase go test ./... +fix: .PHONY ## fix issues found by linters + golangci-lint run --fix ./... + release-vsn: # tags and pushes a new release @read -p "Version: " tag; \ git checkout main; \ diff --git a/algorithms/graph_test.go b/algorithms/graph_test.go index 1266809..599c3ee 100644 --- a/algorithms/graph_test.go +++ b/algorithms/graph_test.go @@ -22,7 +22,7 @@ func TestDFS(t *testing.T) { return nil } - DFS(1, neighbors, visit) + _ = DFS(1, neighbors, visit) assert.Equal(t, res, []int{1, 2, 4, 3}) } @@ -42,7 +42,7 @@ func TestBFS(t *testing.T) { return nil } - BFS(1, neighbors, visit) + _ = BFS(1, neighbors, visit) assert.Equal(t, res, []int{1, 2, 3, 4}) } diff --git a/containers/set.go b/containers/set.go index 7801da5..22f90b3 100644 --- a/containers/set.go +++ b/containers/set.go @@ -60,7 +60,7 @@ func (s Set[V]) Equal(other Set[V]) bool { return false } - for k, _ := range s { + for k := range s { if !other.Has(k) { return false } @@ -77,7 +77,7 @@ func (s Set[V]) Equal(other Set[V]) bool { // s2.Difference(s1) = {a4, a5} func (s Set[V]) Difference(other Set[V]) Set[V] { new := NewSet[V]() - for v, _ := range s { + for v := range s { if !other.Has(v) { new.Add(v) } @@ -93,7 +93,7 @@ func (s Set[V]) Difference(other Set[V]) Set[V] { // s2.Union(s1) = {a1, a2, a3, a4} func (s Set[V]) Union(other Set[V]) Set[V] { new := ToSet(s.List()) - for v, _ := range other { + for v := range other { new.Add(v) } return new @@ -104,7 +104,7 @@ func Union[V comparable](sets ...Set[V]) Set[V] { // use nested loops for a bit of extra efficiency for _, s := range sets { - for v, _ := range s { + for v := range s { res.Add(v) } } @@ -119,7 +119,7 @@ func Union[V comparable](sets ...Set[V]) Set[V] { // s1.Intersect(s2) = {a2} func (s Set[V]) Intersect(other Set[V]) Set[V] { res := NewSet[V]() - for v, _ := range s { + for v := range s { if other.Has(v) { res.Add(v) } @@ -134,7 +134,7 @@ func Intersect[V comparable](sets ...Set[V]) Set[V] { return res } first, rest := sets[0], sets[1:] - for v, _ := range first { + for v := range first { if lo.EveryBy(rest, func(s Set[V]) bool { return s.Has(v) }) { res.Add(v) } diff --git a/containers/stack_test.go b/containers/stack_test.go index cc3260a..35ab6d0 100644 --- a/containers/stack_test.go +++ b/containers/stack_test.go @@ -33,8 +33,8 @@ func TestStackToList(t *testing.T) { s.Push(2) assert.Equal(t, s.List(), []int{2, 3, 1}) - s.Pop() + _, _ = s.Pop() assert.Equal(t, s.List(), []int{3, 1}) - s.Pop() + _, _ = s.Pop() assert.Equal(t, s.List(), []int{1}) } diff --git a/retry/algorithms.go b/retry/algorithms.go index 148337a..7fcdf7b 100644 --- a/retry/algorithms.go +++ b/retry/algorithms.go @@ -24,11 +24,7 @@ func (exp *Exponential) Backoff(iter int) time.Duration { } func (exp *Exponential) Continue() bool { - if exp.max <= exp.start { - return false - } - - return true + return exp.max > exp.start } type Constant struct {