Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Oct 1, 2020
1 parent 5a4afb1 commit e378582
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
56 changes: 56 additions & 0 deletions core/stores/cache/cleaner_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cache

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestNextDelay(t *testing.T) {
tests := []struct {
name string
input time.Duration
output time.Duration
ok bool
}{
{
name: "second",
input: time.Second,
output: time.Second * 5,
ok: true,
},
{
name: "5 seconds",
input: time.Second * 5,
output: time.Minute,
ok: true,
},
{
name: "minute",
input: time.Minute,
output: time.Minute * 5,
ok: true,
},
{
name: "5 minutes",
input: time.Minute * 5,
output: time.Hour,
ok: true,
},
{
name: "hour",
input: time.Hour,
output: 0,
ok: false,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
next, ok := nextDelay(test.input)
assert.Equal(t, test.ok, ok)
assert.Equal(t, test.output, next)
})
}
}
13 changes: 9 additions & 4 deletions core/stores/sqlc/cachedsql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,16 @@ func TestCachedConn_QueryRowIndex_HasCache_IntPrimary(t *testing.T) {
},
}

s, err := miniredis.Run()
if err != nil {
t.Error(err)
}
defer s.Close()

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
resetStats()
s, err := miniredis.Run()
if err != nil {
t.Error(err)
}
s.FlushAll()

r := redis.NewRedis(s.Addr(), redis.NodeType)
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
Expand Down Expand Up @@ -242,6 +245,8 @@ func TestCachedConn_QueryRowIndex_HasWrongCache(t *testing.T) {
if err != nil {
t.Error(err)
}
s.FlushAll()
defer s.Close()

r := redis.NewRedis(s.Addr(), redis.NodeType)
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
Expand Down

0 comments on commit e378582

Please sign in to comment.