Fix Sonart PR1
This commit is contained in:
parent
326fc5dd9c
commit
41d682d878
@ -16,3 +16,6 @@
|
|||||||
- Fix 4444: panic when 404 not found. [4446](https://github.com/beego/beego/pull/4446)
|
- Fix 4444: panic when 404 not found. [4446](https://github.com/beego/beego/pull/4446)
|
||||||
- Fix 4435: fix panic when controller dir not found. [4452](https://github.com/beego/beego/pull/4452)
|
- Fix 4435: fix panic when controller dir not found. [4452](https://github.com/beego/beego/pull/4452)
|
||||||
- Fix 4456: Fix router method expression [4456](https://github.com/beego/beego/pull/4456)
|
- Fix 4456: Fix router method expression [4456](https://github.com/beego/beego/pull/4456)
|
||||||
|
|
||||||
|
## Fix Sonar
|
||||||
|
- []()
|
||||||
70
adapter/cache/cache_test.go
vendored
70
adapter/cache/cache_test.go
vendored
@ -21,10 +21,18 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
initError = "init err"
|
||||||
|
setError = "set Error"
|
||||||
|
checkError = "check err"
|
||||||
|
getError = "get err"
|
||||||
|
getMultiError = "GetMulti Error"
|
||||||
|
)
|
||||||
|
|
||||||
func TestCacheIncr(t *testing.T) {
|
func TestCacheIncr(t *testing.T) {
|
||||||
bm, err := NewCache("memory", `{"interval":20}`)
|
bm, err := NewCache("memory", `{"interval":20}`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("init err")
|
t.Error(initError)
|
||||||
}
|
}
|
||||||
// timeoutDuration := 10 * time.Second
|
// timeoutDuration := 10 * time.Second
|
||||||
|
|
||||||
@ -46,28 +54,28 @@ func TestCacheIncr(t *testing.T) {
|
|||||||
func TestCache(t *testing.T) {
|
func TestCache(t *testing.T) {
|
||||||
bm, err := NewCache("memory", `{"interval":20}`)
|
bm, err := NewCache("memory", `{"interval":20}`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("init err")
|
t.Error(initError)
|
||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v := bm.Get("astaxie"); v.(int) != 1 {
|
if v := bm.Get("astaxie"); v.(int) != 1 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
|
|
||||||
if bm.IsExist("astaxie") {
|
if bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Incr("astaxie"); err != nil {
|
if err = bm.Incr("astaxie"); err != nil {
|
||||||
@ -75,7 +83,7 @@ func TestCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v := bm.Get("astaxie"); v.(int) != 2 {
|
if v := bm.Get("astaxie"); v.(int) != 2 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Decr("astaxie"); err != nil {
|
if err = bm.Decr("astaxie"); err != nil {
|
||||||
@ -83,7 +91,7 @@ func TestCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v := bm.Get("astaxie"); v.(int) != 1 {
|
if v := bm.Get("astaxie"); v.(int) != 1 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
bm.Delete("astaxie")
|
bm.Delete("astaxie")
|
||||||
if bm.IsExist("astaxie") {
|
if bm.IsExist("astaxie") {
|
||||||
@ -92,49 +100,49 @@ func TestCache(t *testing.T) {
|
|||||||
|
|
||||||
// test GetMulti
|
// test GetMulti
|
||||||
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
if v := bm.Get("astaxie"); v.(string) != "author" {
|
if v := bm.Get("astaxie"); v.(string) != "author" {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie1") {
|
if !bm.IsExist("astaxie1") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
vv := bm.GetMulti([]string{"astaxie", "astaxie1"})
|
vv := bm.GetMulti([]string{"astaxie", "astaxie1"})
|
||||||
if len(vv) != 2 {
|
if len(vv) != 2 {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if vv[0].(string) != "author" {
|
if vv[0].(string) != "author" {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if vv[1].(string) != "author1" {
|
if vv[1].(string) != "author1" {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFileCache(t *testing.T) {
|
func TestFileCache(t *testing.T) {
|
||||||
bm, err := NewCache("file", `{"CachePath":"cache","FileSuffix":".bin","DirectoryLevel":"2","EmbedExpiry":"0"}`)
|
bm, err := NewCache("file", `{"CachePath":"cache","FileSuffix":".bin","DirectoryLevel":"2","EmbedExpiry":"0"}`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("init err")
|
t.Error(initError)
|
||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v := bm.Get("astaxie"); v.(int) != 1 {
|
if v := bm.Get("astaxie"); v.(int) != 1 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Incr("astaxie"); err != nil {
|
if err = bm.Incr("astaxie"); err != nil {
|
||||||
@ -142,7 +150,7 @@ func TestFileCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v := bm.Get("astaxie"); v.(int) != 2 {
|
if v := bm.Get("astaxie"); v.(int) != 2 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Decr("astaxie"); err != nil {
|
if err = bm.Decr("astaxie"); err != nil {
|
||||||
@ -150,7 +158,7 @@ func TestFileCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v := bm.Get("astaxie"); v.(int) != 1 {
|
if v := bm.Get("astaxie"); v.(int) != 1 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
bm.Delete("astaxie")
|
bm.Delete("astaxie")
|
||||||
if bm.IsExist("astaxie") {
|
if bm.IsExist("astaxie") {
|
||||||
@ -159,32 +167,32 @@ func TestFileCache(t *testing.T) {
|
|||||||
|
|
||||||
// test string
|
// test string
|
||||||
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
if v := bm.Get("astaxie"); v.(string) != "author" {
|
if v := bm.Get("astaxie"); v.(string) != "author" {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test GetMulti
|
// test GetMulti
|
||||||
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie1") {
|
if !bm.IsExist("astaxie1") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
vv := bm.GetMulti([]string{"astaxie", "astaxie1"})
|
vv := bm.GetMulti([]string{"astaxie", "astaxie1"})
|
||||||
if len(vv) != 2 {
|
if len(vv) != 2 {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if vv[0].(string) != "author" {
|
if vv[0].(string) != "author" {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if vv[1].(string) != "author1" {
|
if vv[1].(string) != "author1" {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.RemoveAll("cache")
|
os.RemoveAll("cache")
|
||||||
|
|||||||
40
adapter/cache/memcache/memcache_test.go
vendored
40
adapter/cache/memcache/memcache_test.go
vendored
@ -24,6 +24,14 @@ import (
|
|||||||
"github.com/beego/beego/v2/adapter/cache"
|
"github.com/beego/beego/v2/adapter/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
initError = "init err"
|
||||||
|
setError = "set Error"
|
||||||
|
checkError = "check err"
|
||||||
|
getError = "get err"
|
||||||
|
getMultiError = "GetMulti Error"
|
||||||
|
)
|
||||||
|
|
||||||
func TestMemcacheCache(t *testing.T) {
|
func TestMemcacheCache(t *testing.T) {
|
||||||
|
|
||||||
addr := os.Getenv("MEMCACHE_ADDR")
|
addr := os.Getenv("MEMCACHE_ADDR")
|
||||||
@ -33,27 +41,27 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
|
|
||||||
bm, err := cache.NewCache("memcache", fmt.Sprintf(`{"conn": "%s"}`, addr))
|
bm, err := cache.NewCache("memcache", fmt.Sprintf(`{"conn": "%s"}`, addr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("init err")
|
t.Error(initError)
|
||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(11 * time.Second)
|
time.Sleep(11 * time.Second)
|
||||||
|
|
||||||
if bm.IsExist("astaxie") {
|
if bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "1", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := strconv.Atoi(string(bm.Get("astaxie").([]byte))); err != nil || v != 1 {
|
if v, err := strconv.Atoi(string(bm.Get("astaxie").([]byte))); err != nil || v != 1 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Incr("astaxie"); err != nil {
|
if err = bm.Incr("astaxie"); err != nil {
|
||||||
@ -61,7 +69,7 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v, err := strconv.Atoi(string(bm.Get("astaxie").([]byte))); err != nil || v != 2 {
|
if v, err := strconv.Atoi(string(bm.Get("astaxie").([]byte))); err != nil || v != 2 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Decr("astaxie"); err != nil {
|
if err = bm.Decr("astaxie"); err != nil {
|
||||||
@ -69,7 +77,7 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v, err := strconv.Atoi(string(bm.Get("astaxie").([]byte))); err != nil || v != 1 {
|
if v, err := strconv.Atoi(string(bm.Get("astaxie").([]byte))); err != nil || v != 1 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
bm.Delete("astaxie")
|
bm.Delete("astaxie")
|
||||||
if bm.IsExist("astaxie") {
|
if bm.IsExist("astaxie") {
|
||||||
@ -78,33 +86,33 @@ func TestMemcacheCache(t *testing.T) {
|
|||||||
|
|
||||||
// test string
|
// test string
|
||||||
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v := bm.Get("astaxie").([]byte); string(v) != "author" {
|
if v := bm.Get("astaxie").([]byte); string(v) != "author" {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test GetMulti
|
// test GetMulti
|
||||||
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie1") {
|
if !bm.IsExist("astaxie1") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
vv := bm.GetMulti([]string{"astaxie", "astaxie1"})
|
vv := bm.GetMulti([]string{"astaxie", "astaxie1"})
|
||||||
if len(vv) != 2 {
|
if len(vv) != 2 {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if string(vv[0].([]byte)) != "author" && string(vv[0].([]byte)) != "author1" {
|
if string(vv[0].([]byte)) != "author" && string(vv[0].([]byte)) != "author1" {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if string(vv[1].([]byte)) != "author1" && string(vv[1].([]byte)) != "author" {
|
if string(vv[1].([]byte)) != "author1" && string(vv[1].([]byte)) != "author" {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test clear all
|
// test clear all
|
||||||
|
|||||||
44
adapter/cache/redis/redis_test.go
vendored
44
adapter/cache/redis/redis_test.go
vendored
@ -25,6 +25,14 @@ import (
|
|||||||
"github.com/beego/beego/v2/adapter/cache"
|
"github.com/beego/beego/v2/adapter/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
initError = "init err"
|
||||||
|
setError = "set Error"
|
||||||
|
checkError = "check err"
|
||||||
|
getError = "get err"
|
||||||
|
getMultiError = "GetMulti Error"
|
||||||
|
)
|
||||||
|
|
||||||
func TestRedisCache(t *testing.T) {
|
func TestRedisCache(t *testing.T) {
|
||||||
redisAddr := os.Getenv("REDIS_ADDR")
|
redisAddr := os.Getenv("REDIS_ADDR")
|
||||||
if redisAddr == "" {
|
if redisAddr == "" {
|
||||||
@ -33,27 +41,27 @@ func TestRedisCache(t *testing.T) {
|
|||||||
|
|
||||||
bm, err := cache.NewCache("redis", fmt.Sprintf(`{"conn": "%s"}`, redisAddr))
|
bm, err := cache.NewCache("redis", fmt.Sprintf(`{"conn": "%s"}`, redisAddr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("init err")
|
t.Error(initError)
|
||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(11 * time.Second)
|
time.Sleep(11 * time.Second)
|
||||||
|
|
||||||
if bm.IsExist("astaxie") {
|
if bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", 1, timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, _ := redis.Int(bm.Get("astaxie"), err); v != 1 {
|
if v, _ := redis.Int(bm.Get("astaxie"), err); v != 1 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Incr("astaxie"); err != nil {
|
if err = bm.Incr("astaxie"); err != nil {
|
||||||
@ -61,7 +69,7 @@ func TestRedisCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v, _ := redis.Int(bm.Get("astaxie"), err); v != 2 {
|
if v, _ := redis.Int(bm.Get("astaxie"), err); v != 2 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bm.Decr("astaxie"); err != nil {
|
if err = bm.Decr("astaxie"); err != nil {
|
||||||
@ -69,7 +77,7 @@ func TestRedisCache(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v, _ := redis.Int(bm.Get("astaxie"), err); v != 1 {
|
if v, _ := redis.Int(bm.Get("astaxie"), err); v != 1 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
bm.Delete("astaxie")
|
bm.Delete("astaxie")
|
||||||
if bm.IsExist("astaxie") {
|
if bm.IsExist("astaxie") {
|
||||||
@ -78,33 +86,33 @@ func TestRedisCache(t *testing.T) {
|
|||||||
|
|
||||||
// test string
|
// test string
|
||||||
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie", "author", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie") {
|
if !bm.IsExist("astaxie") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, _ := redis.String(bm.Get("astaxie"), err); v != "author" {
|
if v, _ := redis.String(bm.Get("astaxie"), err); v != "author" {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test GetMulti
|
// test GetMulti
|
||||||
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
if err = bm.Put("astaxie1", "author1", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !bm.IsExist("astaxie1") {
|
if !bm.IsExist("astaxie1") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
vv := bm.GetMulti([]string{"astaxie", "astaxie1"})
|
vv := bm.GetMulti([]string{"astaxie", "astaxie1"})
|
||||||
if len(vv) != 2 {
|
if len(vv) != 2 {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if v, _ := redis.String(vv[0], nil); v != "author" {
|
if v, _ := redis.String(vv[0], nil); v != "author" {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if v, _ := redis.String(vv[1], nil); v != "author1" {
|
if v, _ := redis.String(vv[1], nil); v != "author1" {
|
||||||
t.Error("GetMulti ERROR")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test clear all
|
// test clear all
|
||||||
@ -118,12 +126,12 @@ func TestCache_Scan(t *testing.T) {
|
|||||||
// init
|
// init
|
||||||
bm, err := cache.NewCache("redis", `{"conn": "127.0.0.1:6379"}`)
|
bm, err := cache.NewCache("redis", `{"conn": "127.0.0.1:6379"}`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("init err")
|
t.Error(initError)
|
||||||
}
|
}
|
||||||
// insert all
|
// insert all
|
||||||
for i := 0; i < 10000; i++ {
|
for i := 0; i < 10000; i++ {
|
||||||
if err = bm.Put(fmt.Sprintf("astaxie%d", i), fmt.Sprintf("author%d", i), timeoutDuration); err != nil {
|
if err = bm.Put(fmt.Sprintf("astaxie%d", i), fmt.Sprintf("author%d", i), timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
44
adapter/cache/ssdb/ssdb_test.go
vendored
44
adapter/cache/ssdb/ssdb_test.go
vendored
@ -10,6 +10,14 @@ import (
|
|||||||
"github.com/beego/beego/v2/adapter/cache"
|
"github.com/beego/beego/v2/adapter/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
initError = "init err"
|
||||||
|
setError = "set Error"
|
||||||
|
checkError = "check err"
|
||||||
|
getError = "get err"
|
||||||
|
getMultiError = "GetMulti Error"
|
||||||
|
)
|
||||||
|
|
||||||
func TestSsdbcacheCache(t *testing.T) {
|
func TestSsdbcacheCache(t *testing.T) {
|
||||||
ssdbAddr := os.Getenv("SSDB_ADDR")
|
ssdbAddr := os.Getenv("SSDB_ADDR")
|
||||||
if ssdbAddr == "" {
|
if ssdbAddr == "" {
|
||||||
@ -18,25 +26,25 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
|
|
||||||
ssdb, err := cache.NewCache("ssdb", fmt.Sprintf(`{"conn": "%s"}`, ssdbAddr))
|
ssdb, err := cache.NewCache("ssdb", fmt.Sprintf(`{"conn": "%s"}`, ssdbAddr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("init err")
|
t.Error(initError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test put and exist
|
// test put and exist
|
||||||
if ssdb.IsExist("ssdb") {
|
if ssdb.IsExist("ssdb") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
timeoutDuration := 10 * time.Second
|
timeoutDuration := 10 * time.Second
|
||||||
// timeoutDuration := -10*time.Second if timeoutDuration is negtive,it means permanent
|
// timeoutDuration := -10*time.Second if timeoutDuration is negtive,it means permanent
|
||||||
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration); err != nil {
|
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !ssdb.IsExist("ssdb") {
|
if !ssdb.IsExist("ssdb") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get test done
|
// Get test done
|
||||||
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration); err != nil {
|
if err = ssdb.Put("ssdb", "ssdb", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v := ssdb.Get("ssdb"); v != "ssdb" {
|
if v := ssdb.Get("ssdb"); v != "ssdb" {
|
||||||
@ -45,14 +53,14 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
|
|
||||||
// inc/dec test done
|
// inc/dec test done
|
||||||
if err = ssdb.Put("ssdb", "2", timeoutDuration); err != nil {
|
if err = ssdb.Put("ssdb", "2", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if err = ssdb.Incr("ssdb"); err != nil {
|
if err = ssdb.Incr("ssdb"); err != nil {
|
||||||
t.Error("incr Error", err)
|
t.Error("incr Error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := strconv.Atoi(ssdb.Get("ssdb").(string)); err != nil || v != 3 {
|
if v, err := strconv.Atoi(ssdb.Get("ssdb").(string)); err != nil || v != 3 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = ssdb.Decr("ssdb"); err != nil {
|
if err = ssdb.Decr("ssdb"); err != nil {
|
||||||
@ -61,10 +69,10 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
|
|
||||||
// test del
|
// test del
|
||||||
if err = ssdb.Put("ssdb", "3", timeoutDuration); err != nil {
|
if err = ssdb.Put("ssdb", "3", timeoutDuration); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if v, err := strconv.Atoi(ssdb.Get("ssdb").(string)); err != nil || v != 3 {
|
if v, err := strconv.Atoi(ssdb.Get("ssdb").(string)); err != nil || v != 3 {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
if err := ssdb.Delete("ssdb"); err == nil {
|
if err := ssdb.Delete("ssdb"); err == nil {
|
||||||
if ssdb.IsExist("ssdb") {
|
if ssdb.IsExist("ssdb") {
|
||||||
@ -74,31 +82,31 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
|
|
||||||
// test string
|
// test string
|
||||||
if err = ssdb.Put("ssdb", "ssdb", -10*time.Second); err != nil {
|
if err = ssdb.Put("ssdb", "ssdb", -10*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !ssdb.IsExist("ssdb") {
|
if !ssdb.IsExist("ssdb") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
if v := ssdb.Get("ssdb").(string); v != "ssdb" {
|
if v := ssdb.Get("ssdb").(string); v != "ssdb" {
|
||||||
t.Error("get err")
|
t.Error(getError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test GetMulti done
|
// test GetMulti done
|
||||||
if err = ssdb.Put("ssdb1", "ssdb1", -10*time.Second); err != nil {
|
if err = ssdb.Put("ssdb1", "ssdb1", -10*time.Second); err != nil {
|
||||||
t.Error("set Error", err)
|
t.Error(setError, err)
|
||||||
}
|
}
|
||||||
if !ssdb.IsExist("ssdb1") {
|
if !ssdb.IsExist("ssdb1") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
vv := ssdb.GetMulti([]string{"ssdb", "ssdb1"})
|
vv := ssdb.GetMulti([]string{"ssdb", "ssdb1"})
|
||||||
if len(vv) != 2 {
|
if len(vv) != 2 {
|
||||||
t.Error("getmulti error")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if vv[0].(string) != "ssdb" {
|
if vv[0].(string) != "ssdb" {
|
||||||
t.Error("getmulti error")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
if vv[1].(string) != "ssdb1" {
|
if vv[1].(string) != "ssdb1" {
|
||||||
t.Error("getmulti error")
|
t.Error(getMultiError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test clear all done
|
// test clear all done
|
||||||
@ -106,6 +114,6 @@ func TestSsdbcacheCache(t *testing.T) {
|
|||||||
t.Error("clear all err")
|
t.Error("clear all err")
|
||||||
}
|
}
|
||||||
if ssdb.IsExist("ssdb") || ssdb.IsExist("ssdb1") {
|
if ssdb.IsExist("ssdb") || ssdb.IsExist("ssdb1") {
|
||||||
t.Error("check err")
|
t.Error(checkError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,7 +81,8 @@ password = ${GOPATH}
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
f, err := os.Create("testini.conf")
|
cfgFile := "testini.conf"
|
||||||
|
f, err := os.Create(cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -91,8 +92,8 @@ password = ${GOPATH}
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
defer os.Remove("testini.conf")
|
defer os.Remove(cfgFile)
|
||||||
iniconf, err := NewConfig("ini", "testini.conf")
|
iniconf, err := NewConfig("ini", cfgFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,8 @@ func TestJsonStartsWithArray(t *testing.T) {
|
|||||||
"serviceAPI": "http://www.test.com/employee"
|
"serviceAPI": "http://www.test.com/employee"
|
||||||
}
|
}
|
||||||
]`
|
]`
|
||||||
f, err := os.Create("testjsonWithArray.conf")
|
cfgFileName := "testjsonWithArray.conf"
|
||||||
|
f, err := os.Create(cfgFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -42,8 +43,8 @@ func TestJsonStartsWithArray(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
defer os.Remove("testjsonWithArray.conf")
|
defer os.Remove(cfgFileName)
|
||||||
jsonconf, err := NewConfig("json", "testjsonWithArray.conf")
|
jsonconf, err := NewConfig("json", cfgFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -132,7 +133,8 @@ func TestJson(t *testing.T) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
f, err := os.Create("testjson.conf")
|
cfgFileName := "testjson.conf"
|
||||||
|
f, err := os.Create(cfgFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -142,8 +144,8 @@ func TestJson(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
defer os.Remove("testjson.conf")
|
defer os.Remove(cfgFileName)
|
||||||
jsonconf, err := NewConfig("json", "testjson.conf")
|
jsonconf, err := NewConfig("json", cfgFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,7 +58,8 @@ func TestXML(t *testing.T) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
f, err := os.Create("testxml.conf")
|
cfgFileName := "testxml.conf"
|
||||||
|
f, err := os.Create(cfgFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -68,9 +69,9 @@ func TestXML(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
defer os.Remove("testxml.conf")
|
defer os.Remove(cfgFileName)
|
||||||
|
|
||||||
xmlconf, err := config.NewConfig("xml", "testxml.conf")
|
xmlconf, err := config.NewConfig("xml", cfgFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,7 +54,8 @@ func TestYaml(t *testing.T) {
|
|||||||
"emptystrings": []string{},
|
"emptystrings": []string{},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
f, err := os.Create("testyaml.conf")
|
cfgFileName := "testyaml.conf"
|
||||||
|
f, err := os.Create(cfgFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -64,8 +65,8 @@ func TestYaml(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
defer os.Remove("testyaml.conf")
|
defer os.Remove(cfgFileName)
|
||||||
yamlconf, err := config.NewConfig("yaml", "testyaml.conf")
|
yamlconf, err := config.NewConfig("yaml", cfgFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,8 @@ import (
|
|||||||
"github.com/beego/beego/v2/adapter/context"
|
"github.com/beego/beego/v2/adapter/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
// Demo is used to test, it's empty
|
||||||
func Demo(i int) {
|
func Demo(i int) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,11 +85,7 @@ func ValuesCompare(is bool, a interface{}, args ...interface{}) (ok bool, err er
|
|||||||
}
|
}
|
||||||
ok = is && ok || !is && !ok
|
ok = is && ok || !is && !ok
|
||||||
if !ok {
|
if !ok {
|
||||||
if is {
|
err = fmt.Errorf("expected: `%v`, get `%v`", b, a)
|
||||||
err = fmt.Errorf("expected: `%v`, get `%v`", b, a)
|
|
||||||
} else {
|
|
||||||
err = fmt.Errorf("expected: `%v`, get `%v`", b, a)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wrongArg:
|
wrongArg:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user