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