Skip to content

Commit

Permalink
增加 redis 单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
xmdhs committed Oct 12, 2023
1 parent 1e5e670 commit 1577bc9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ jobs:
run: |
bash build.sh
- name: start mysql
- name: start mysql / redis
run: |
sudo systemctl start mysql.service
apt update
apt install redis
- name: Test
run: go test -tags="redis,sqlite" -race -v ./...
Expand Down
38 changes: 38 additions & 0 deletions db/cache/redis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//go:build redis

package cache

import (
"testing"
"time"

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

func TestRedis(t *testing.T) {
c := NewRedis("127.0.0.1:6379", "")

key := []byte("key")
value := []byte("value")

require.Nil(t, c.Put(key, value, time.Now().Add(1*time.Hour)))

v, err := c.Get(key)
require.Nil(t, err)

assert.Equal(t, v, value)

require.Nil(t, c.Del(key))

v, err = c.Get(key)
require.Nil(t, err)
require.Nil(t, v)

require.Nil(t, c.Put(key, value, time.Now().Add(2*time.Second)))
time.Sleep(3 * time.Second)

v, err = c.Get(key)
require.Nil(t, err)
require.Nil(t, v)
}
1 change: 1 addition & 0 deletions service/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"testing"

_ "github.com/go-sql-driver/mysql"
"github.com/samber/lo"
"github.com/xmdhs/authlib-skin/config"
"github.com/xmdhs/authlib-skin/db/cache"
Expand Down

0 comments on commit 1577bc9

Please sign in to comment.