修复RedisCommand BUG + 增加单元测试

This commit is contained in:
白茶清欢 2025-04-20 13:40:39 +08:00
parent 653843dc02
commit 299edfcc9a
4 changed files with 49 additions and 2 deletions

12
go.mod
View File

@ -1,3 +1,13 @@
module git.zhangdeman.cn/zhangdeman/consts module git.zhangdeman.cn/zhangdeman/consts
go 1.19 go 1.23.0
toolchain go1.24.2
require github.com/smartystreets/goconvey v1.8.1
require (
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/smarty/assertions v1.15.0 // indirect
)

8
go.sum Normal file
View File

@ -0,0 +1,8 @@
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=

View File

@ -17,7 +17,7 @@ func (rc *RedisCmd) MarshalJSON() ([]byte, error) {
return []byte(rc.String()), nil return []byte(rc.String()), nil
} }
const ( var (
RedisCommandExists RedisCmd = "EXISTS" RedisCommandExists RedisCmd = "EXISTS"
RedisCommandTTL RedisCmd = "TTL" RedisCommandTTL RedisCmd = "TTL"
RedisCommandSet RedisCmd = "SET" RedisCommandSet RedisCmd = "SET"

29
redis_test.go Normal file
View File

@ -0,0 +1,29 @@
// Package consts ...
//
// Description : consts ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-04-20 13:29
package consts
import (
"encoding/json"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
// RedisCmd_String 序列换 RedisCmd
func TestRedisCmd_String(t *testing.T) {
Convey("redis cmd字符串值", t, func() {
byteData, err := json.Marshal(RedisCommandSet)
So(err, ShouldBeNil)
So(RedisCommandSet.String(), ShouldEqual, "SET")
So(string(byteData), ShouldEqual, `"SET"`)
})
Convey("redis cmd MarshalJSON", t, func() {
str, err := RedisCommandSet.MarshalJSON()
So(err, ShouldBeNil)
So(string(str), ShouldEqual, `SET`)
})
}