Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkurev committed Jun 5, 2022
1 parent 91d70d4 commit 94d5ca9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions gcache_test.go
Expand Up @@ -463,4 +463,11 @@ func TestCacheStats(t *testing.T) {
assert.True(t, ok)
assert.Equal(t, s.ClearCount, goroutines)
assert.Equal(t, s.ErrClearCount, 0)

c.ResetStats()

s, ok = c.Stats()
assert.True(t, ok)
assert.Equal(t, s.ReadBytes, 0)
assert.Equal(t, s.WriteBytes, 0)
}
20 changes: 20 additions & 0 deletions internal/hasher/hasher_test.go
Expand Up @@ -2,6 +2,7 @@ package hasher

import (
"errors"
"fmt"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
Expand Down Expand Up @@ -36,4 +37,23 @@ func TestMsgpackHasher(t *testing.T) {
k, err = h.Hash(m)
assert.Nil(t, err)
assert.Equal(t, k, "e4ff5e7d7a7f08e9800a3e25cb774533cb20040df30b6ba10f956f9acd0eb3f7")

_, err = h.Hash(nil)
assert.Nil(t, err)
assert.Equal(t, k, "e4ff5e7d7a7f08e9800a3e25cb774533cb20040df30b6ba10f956f9acd0eb3f7")

unsupportedTypes := map[string]any{
"msgpack: Encode(unsupported func())": func() {},
"msgpack: Encode(unsupported chan int)": make(chan int),
"msgpack: Encode(unsupported complex128)": complex(10, 11),
}

for s, anyType := range unsupportedTypes {
_, err = h.Hash(anyType)
assert.NotNil(t, err)
e, ok := err.(*Error)
assert.True(t, ok)
assert.Equal(t, e.Error(), fmt.Sprintf("error when hashing object of type %T: %s", anyType, s))
assert.Equal(t, e.Unwrap().Error(), s)
}
}
9 changes: 8 additions & 1 deletion store/sqlite_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"github.com/stretchr/testify/assert"
"os"
"sync"
"testing"
)
Expand Down Expand Up @@ -48,8 +49,14 @@ func TestSQLiteStore_Context(t *testing.T) {
}

func TestSQLiteStore(t *testing.T) {
filename := "test.db"
if _, err := os.Stat(filename); err == nil {
err := os.Remove(filename)
assert.Nil(t, err)
}

ctx := context.Background()
db, err := sql.Open("sqlite3", "test.db")
db, err := sql.Open("sqlite3", filename)
assert.Nil(t, err)
s, err := SQLiteStore(ctx, db)
assert.Nil(t, err)
Expand Down

0 comments on commit 94d5ca9

Please sign in to comment.