diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..d0460a5 --- /dev/null +++ b/.github/workflows/go.yml @@ -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 ./... diff --git a/keeper_test.go b/keeper_test.go index d8a4c6b..2897924 100644 --- a/keeper_test.go +++ b/keeper_test.go @@ -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, @@ -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, @@ -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) { @@ -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() @@ -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() @@ -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) { @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) } diff --git a/keeper_with_failover.go b/keeper_with_failover.go index 8246d6c..743ad8a 100644 --- a/keeper_with_failover.go +++ b/keeper_with_failover.go @@ -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" ) @@ -217,6 +218,7 @@ 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 @@ -224,6 +226,7 @@ func (k *KeeperWithFailover) StoreNil(cacheKey string) error { return errs.ErrorOrNil() } +// DeleteByKeys :nodoc: func (k *KeeperWithFailover) DeleteByKeys(keys []string) error { if k.disableCaching { return nil @@ -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 } diff --git a/keeper_with_failover_test.go b/keeper_with_failover_test.go index 5175a28..f469bfe 100644 --- a/keeper_with_failover_test.go +++ b/keeper_with_failover_test.go @@ -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, @@ -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, @@ -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) { @@ -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)) }