Skip to content

Commit

Permalink
Merge pull request #41 from bagastri07/feature/BAN-15007-github-actio…
Browse files Browse the repository at this point in the history
…n-to-run-unit-test

feature: add GitHub action to run golangci-lint, unit test, and go build
  • Loading branch information
aslamhadi authored Dec 14, 2022
2 parents 984b85e + 508e661 commit eb5fe46
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Go

on: [pull_request]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18

- name: Golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.46.2
args: --print-issued-lines=false --exclude-use-default=false --enable=revive --enable=goimports --enable=unconvert --concurrency=2

- name: Test
run: go test -v ./...

- name: Build
run: go build -v ./...
15 changes: 4 additions & 11 deletions keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestGetOrSet(t *testing.T) {
TestString: "string",
TestInt64: 1640995120740899877,
TestFloat64: 234.23324,
TestTime: time.UnixMilli(3276483223),
TestTime: time.UnixMilli(3276483223).UTC(),
TestNilString: nil,
TestNilInt64: nil,
TestNilFloat64: nil,
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestGetHashMemberOrSet(t *testing.T) {
TestString: "string",
TestInt64: 1640995120740899877,
TestFloat64: 234.23324,
TestTime: time.UnixMilli(3276483223),
TestTime: time.UnixMilli(3276483223).UTC(),
TestNilString: nil,
TestNilInt64: nil,
TestNilFloat64: nil,
Expand Down Expand Up @@ -605,7 +605,6 @@ func TestGetLockStoreRightLeftList(t *testing.T) {
resultList, _ := redigo.Strings(res2, nil)
assert.EqualValues(t, multiList, resultList)
assert.NoError(t, err2)

}

func TestGetAndRemoveFirstAndLastListElement(t *testing.T) {
Expand Down Expand Up @@ -640,8 +639,8 @@ func TestGetAndRemoveFirstAndLastListElement(t *testing.T) {
lastElement, _ := redigo.String(res4, nil)
assert.EqualValues(t, lastElement, "test-response-3")
assert.NoError(t, err4)

}

func TestGetListLength(t *testing.T) {
// Initialize new cache keeper
k := NewKeeper()
Expand All @@ -665,8 +664,8 @@ func TestGetListLength(t *testing.T) {
res3, err3 := k.GetListLength(name)
assert.EqualValues(t, res3, 2)
assert.NoError(t, err3)

}

func TestGetTTL(t *testing.T) {
// Initialize new cache keeper
k := NewKeeper()
Expand All @@ -690,7 +689,6 @@ func TestGetTTL(t *testing.T) {
assert.NotEqual(t, ttl, 0)
var typeInt64 int64
assert.IsType(t, typeInt64, ttl)

}

func TestStoreNil(t *testing.T) {
Expand Down Expand Up @@ -856,7 +854,6 @@ func TestGetOrLock(t *testing.T) {
t.Run("locked got wait too long", func(t *testing.T) {
k := NewKeeper()
m, err := miniredis.Run()

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -885,7 +882,6 @@ func TestGetHashMemberOrLock(t *testing.T) {
t.Run("cache miss", func(t *testing.T) {
k := NewKeeper()
m, err := miniredis.Run()

if err != nil {
t.Fatal(err)
}
Expand All @@ -911,7 +907,6 @@ func TestGetHashMemberOrLock(t *testing.T) {
t.Run("locked got nil", func(t *testing.T) {
k := NewKeeper()
m, err := miniredis.Run()

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -955,7 +950,6 @@ func TestGetHashMemberOrLock(t *testing.T) {
t.Run("locked got result", func(t *testing.T) {
k := NewKeeper()
m, err := miniredis.Run()

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1001,7 +995,6 @@ func TestGetHashMemberOrLock(t *testing.T) {
t.Run("locked got wait too long", func(t *testing.T) {
k := NewKeeper()
m, err := miniredis.Run()

if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 5 additions & 2 deletions keeper_with_failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cacher
import (
"encoding/json"
"errors"
"github.com/hashicorp/go-multierror"
"time"

"github.com/hashicorp/go-multierror"

redigo "github.com/gomodule/redigo/redis"
)

Expand Down Expand Up @@ -217,13 +218,15 @@ func (k *KeeperWithFailover) StoreHashMemberFailover(identifier string, c Item)
return
}

// StoreNil :nodoc:
func (k *KeeperWithFailover) StoreNil(cacheKey string) error {
item := NewItemWithCustomTTL(cacheKey, nilValue, k.nilTTL)
var errs *multierror.Error
errs = multierror.Append(errs, k.StoreWithoutBlocking(item), k.StoreFailover(item))
return errs.ErrorOrNil()
}

// DeleteByKeys :nodoc:
func (k *KeeperWithFailover) DeleteByKeys(keys []string) error {
if k.disableCaching {
return nil
Expand All @@ -250,7 +253,7 @@ func (k *KeeperWithFailover) DeleteByKeys(keys []string) error {
}

// DeleteHashMember :nodoc:
func (k *KeeperWithFailover) DeleteHashMember(identifier string, key string) (error) {
func (k *KeeperWithFailover) DeleteHashMember(identifier string, key string) error {
if k.disableCaching {
return nil
}
Expand Down
7 changes: 3 additions & 4 deletions keeper_with_failover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Test_keeperWithFailover_GetOrSet(t *testing.T) {
TestString: "string",
TestInt64: 1640995120740899877,
TestFloat64: 234.23324,
TestTime: time.UnixMilli(3276483223),
TestTime: time.UnixMilli(3276483223).UTC(),
TestNilString: nil,
TestNilInt64: nil,
TestNilFloat64: nil,
Expand Down Expand Up @@ -149,7 +149,7 @@ func Test_keeperWithFailover_GetHashMemberOrSet(t *testing.T) {
TestString: "string",
TestInt64: 1640995120740899877,
TestFloat64: 234.23324,
TestTime: time.UnixMilli(3276483223),
TestTime: time.UnixMilli(3276483223).UTC(),
TestNilString: nil,
TestNilInt64: nil,
TestNilFloat64: nil,
Expand Down Expand Up @@ -246,7 +246,6 @@ func Test_keeperWithFailover_GetHashMemberOrSet(t *testing.T) {
require.NoError(t, err)
assert.Nil(t, myVar)
})

}

func Test_keeperWithFailover_StoreNil(t *testing.T) {
Expand Down Expand Up @@ -353,5 +352,5 @@ func Test_keeperWithFailover_DeleteHashMember(t *testing.T) {
assert.True(t, m.Exists(identifier) && mFO.Exists(identifier))
err = k.DeleteHashMember(identifier, "key")
assert.NoError(t, err)
assert.False(t, m.Exists(identifier) || m.Exists(identifier))
assert.False(t, m.Exists(identifier))
}

0 comments on commit eb5fe46

Please sign in to comment.