From 55eca1c7b2f7782088943c8c03d250c38cb80bd4 Mon Sep 17 00:00:00 2001 From: Muhammed Efe Cetin Date: Fri, 15 Sep 2023 00:19:11 +0300 Subject: [PATCH] use testify on coherence storage --- coherence/coherence_test.go | 135 ++++++++++++++++++------------------ coherence/go.mod | 14 +++- coherence/go.sum | 16 ++++- 3 files changed, 92 insertions(+), 73 deletions(-) diff --git a/coherence/coherence_test.go b/coherence/coherence_test.go index aa8a24b0..49b30c23 100644 --- a/coherence/coherence_test.go +++ b/coherence/coherence_test.go @@ -4,7 +4,7 @@ package coherence * Copyright © 2023, Oracle and/or its affiliates. */ import ( - "github.com/gofiber/utils" + "github.com/stretchr/testify/require" "testing" "time" ) @@ -22,7 +22,7 @@ func newTestStore(t testing.TB, config ...Config) (*Storage, error) { t.Helper() testStore, err := New(config...) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore.Reset() @@ -33,148 +33,147 @@ func Test_Coherence_Set_And_Get(t *testing.T) { var val []byte testStore, err := newTestStore(t) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore.Set(key1, value1, 0) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) val, err = testStore.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, value1, val) + require.NoError(t, err) + require.Equal(t, value1, val) - utils.AssertEqual(t, true, testStore.Conn() != nil) - - utils.AssertEqual(t, testStore.Close(), nil) + require.NotNil(t, testStore.Conn()) + require.Equal(t, nil, testStore.Close()) } func Test_Coherence_Set_Override(t *testing.T) { var val []byte testStore, err := newTestStore(t) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore.Set(key1, value1, 0) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore.Set(key1, value2, 0) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) val, err = testStore.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, value2, val) + require.NoError(t, err) + require.Equal(t, value2, val) - utils.AssertEqual(t, testStore.Close(), nil) + require.Equal(t, nil, testStore.Close()) } func Test_Coherence_Set_With_Reset(t *testing.T) { var val []byte testStore, err := newTestStore(t) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore.Set(key1, value1, 0) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) val, err = testStore.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, value1, val) + require.NoError(t, err) + require.Equal(t, value1, val) // get a new store but reset it, so the subsequent Get will return nil testStore, err = newTestStore(t, Config{Reset: true}) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) val, err = testStore.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, true, len(val) == 0) + require.NoError(t, err) + require.True(t, len(val) == 0) - utils.AssertEqual(t, testStore.Close(), nil) + require.Equal(t, nil, testStore.Close()) } func Test_Coherence_Set_With_Expiry(t *testing.T) { var val []byte testStore, err := newTestStore(t) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) // set with an expiry of 5 seconds err = testStore.Set(key1, value1, time.Duration(5)*time.Second) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) time.Sleep(time.Duration(6) * time.Second) val, err = testStore.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, true, len(val) == 0) + require.NoError(t, err) + require.True(t, len(val) == 0) - utils.AssertEqual(t, testStore.Close(), nil) + require.Equal(t, nil, testStore.Close()) } func Test_Coherence_Get_Missing(t *testing.T) { var val []byte testStore, err := newTestStore(t) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) val, err = testStore.Get(missingKey) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, true, len(val) == 0) + require.NoError(t, err) + require.True(t, len(val) == 0) - utils.AssertEqual(t, testStore.Close(), nil) + require.Equal(t, nil, testStore.Close()) } func Test_Coherence_Reset(t *testing.T) { var val []byte testStore, err := newTestStore(t) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore.Set(key1, value1, 0) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore.Set(key2, value2, 0) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) // check the keys exist val, err = testStore.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, value1, val) + require.NoError(t, err) + require.Equal(t, value1, val) val, err = testStore.Get(key2) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, value2, val) + require.NoError(t, err) + require.Equal(t, value2, val) // reset the store, this should remove both entries err = testStore.Reset() // check the keys have expired val, err = testStore.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, true, len(val) == 0) + require.NoError(t, err) + require.True(t, len(val) == 0) val, err = testStore.Get(key2) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, true, len(val) == 0) + require.NoError(t, err) + require.True(t, len(val) == 0) - utils.AssertEqual(t, testStore.Close(), nil) + require.Equal(t, nil, testStore.Close()) } func Test_Coherence_Set_And_Delete(t *testing.T) { var val []byte testStore, err := newTestStore(t) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore.Set(key1, value1, 0) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore.Delete(key1) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) // ensure the key has gone val, err = testStore.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, true, len(val) == 0) + require.NoError(t, err) + require.True(t, len(val) == 0) - utils.AssertEqual(t, testStore.Close(), nil) + require.Equal(t, nil, testStore.Close()) } // TestCoherenceWithScope ensures we can create multiple session stores with multiple scopes. @@ -183,34 +182,34 @@ func Test_Coherence_With_Scope(t *testing.T) { // create two session stores with different scopes testStore1, err := newTestStore(t, Config{ScopeName: "scope1"}) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) testStore2, err := newTestStore(t, Config{ScopeName: "scope2"}) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) // ensure we can put the same key with different values in each scope err = testStore1.Set(key1, value1, 0) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) err = testStore2.Set(key1, value2, 0) - utils.AssertEqual(t, err, nil) + require.NoError(t, err) // ensure the value of "key1" is different for each store val, err = testStore1.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, value1, val) + require.NoError(t, err) + require.Equal(t, value1, val) val, err = testStore2.Get(key1) - utils.AssertEqual(t, err, nil) - utils.AssertEqual(t, value2, val) + require.NoError(t, err) + require.Equal(t, value2, val) - utils.AssertEqual(t, testStore1.Close(), nil) - utils.AssertEqual(t, testStore2.Close(), nil) + require.NoError(t, testStore1.Close()) + require.NoError(t, testStore2.Close()) } func Benchmark_Coherence_Set(b *testing.B) { testStore, err := newTestStore(b) - utils.AssertEqual(b, nil, err) + require.NoError(b, err) b.ReportAllocs() b.ResetTimer() @@ -219,15 +218,15 @@ func Benchmark_Coherence_Set(b *testing.B) { err = testStore.Set("john", []byte("doe"), 0) } - utils.AssertEqual(b, nil, err) + require.NoError(b, err) } func Benchmark_Coherence_Get(b *testing.B) { testStore, err := newTestStore(b) - utils.AssertEqual(b, nil, err) + require.NoError(b, err) err = testStore.Set("john", []byte("doe"), 0) - utils.AssertEqual(b, nil, err) + require.NoError(b, err) b.ReportAllocs() b.ResetTimer() @@ -236,15 +235,15 @@ func Benchmark_Coherence_Get(b *testing.B) { _, err = testStore.Get("john") } - utils.AssertEqual(b, nil, err) + require.NoError(b, err) } func Benchmark_Coherence_Delete(b *testing.B) { testStore, err := newTestStore(b) - utils.AssertEqual(b, nil, err) + require.NoError(b, err) err = testStore.Set("john", []byte("doe"), 0) - utils.AssertEqual(b, nil, err) + require.NoError(b, err) b.ReportAllocs() b.ResetTimer() @@ -253,5 +252,5 @@ func Benchmark_Coherence_Delete(b *testing.B) { err = testStore.Delete("john") } - utils.AssertEqual(b, nil, err) + require.NoError(b, err) } diff --git a/coherence/go.mod b/coherence/go.mod index af574f28..8a2e7ef3 100644 --- a/coherence/go.mod +++ b/coherence/go.mod @@ -2,12 +2,20 @@ module github.com/gofiber/storage/coherence go 1.19 -require github.com/oracle/coherence-go-client v1.0.1 +require ( + github.com/oracle/coherence-go-client v1.0.1 + github.com/stretchr/testify v1.8.4 +) -require google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) require ( - github.com/gofiber/utils v1.1.0 github.com/golang/protobuf v1.5.3 // indirect github.com/google/uuid v1.3.1 // indirect golang.org/x/net v0.14.0 // indirect diff --git a/coherence/go.sum b/coherence/go.sum index 055f2504..7e9ad78c 100644 --- a/coherence/go.sum +++ b/coherence/go.sum @@ -1,5 +1,6 @@ -github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= -github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= @@ -7,9 +8,16 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= github.com/oracle/coherence-go-client v1.0.1 h1:MJ9S46+G8DHg/b3c/XB+mGA58wmTE0HdBCH1t+WrIBs= github.com/oracle/coherence-go-client v1.0.1/go.mod h1:tdIKuX6brsdTCARlbxeRYiOF0TA4tA8ujHO4BCS1mjk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= @@ -25,4 +33,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=