2016-04-18 11:16:39 +00:00
|
|
|
package beego
|
|
|
|
|
|
|
|
import (
|
2020-07-06 15:04:29 +00:00
|
|
|
"encoding/json"
|
2016-04-18 11:16:39 +00:00
|
|
|
"fmt"
|
2020-07-06 15:04:29 +00:00
|
|
|
"net/http/httptest"
|
2016-06-01 11:57:08 +00:00
|
|
|
"testing"
|
2016-04-18 11:16:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestList_01(t *testing.T) {
|
2018-08-20 20:55:50 +00:00
|
|
|
m := make(M)
|
2016-04-18 11:16:39 +00:00
|
|
|
list("BConfig", BConfig, m)
|
|
|
|
t.Log(m)
|
|
|
|
om := oldMap()
|
|
|
|
for k, v := range om {
|
2016-06-01 11:57:08 +00:00
|
|
|
if fmt.Sprint(m[k]) != fmt.Sprint(v) {
|
|
|
|
t.Log(k, "old-key", v, "new-key", m[k])
|
2016-04-18 11:16:39 +00:00
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 20:55:50 +00:00
|
|
|
func oldMap() M {
|
|
|
|
m := make(M)
|
2016-04-18 11:16:39 +00:00
|
|
|
m["BConfig.AppName"] = BConfig.AppName
|
|
|
|
m["BConfig.RunMode"] = BConfig.RunMode
|
|
|
|
m["BConfig.RouterCaseSensitive"] = BConfig.RouterCaseSensitive
|
|
|
|
m["BConfig.ServerName"] = BConfig.ServerName
|
|
|
|
m["BConfig.RecoverPanic"] = BConfig.RecoverPanic
|
|
|
|
m["BConfig.CopyRequestBody"] = BConfig.CopyRequestBody
|
|
|
|
m["BConfig.EnableGzip"] = BConfig.EnableGzip
|
|
|
|
m["BConfig.MaxMemory"] = BConfig.MaxMemory
|
|
|
|
m["BConfig.EnableErrorsShow"] = BConfig.EnableErrorsShow
|
|
|
|
m["BConfig.Listen.Graceful"] = BConfig.Listen.Graceful
|
|
|
|
m["BConfig.Listen.ServerTimeOut"] = BConfig.Listen.ServerTimeOut
|
|
|
|
m["BConfig.Listen.ListenTCP4"] = BConfig.Listen.ListenTCP4
|
|
|
|
m["BConfig.Listen.EnableHTTP"] = BConfig.Listen.EnableHTTP
|
|
|
|
m["BConfig.Listen.HTTPAddr"] = BConfig.Listen.HTTPAddr
|
|
|
|
m["BConfig.Listen.HTTPPort"] = BConfig.Listen.HTTPPort
|
|
|
|
m["BConfig.Listen.EnableHTTPS"] = BConfig.Listen.EnableHTTPS
|
|
|
|
m["BConfig.Listen.HTTPSAddr"] = BConfig.Listen.HTTPSAddr
|
|
|
|
m["BConfig.Listen.HTTPSPort"] = BConfig.Listen.HTTPSPort
|
|
|
|
m["BConfig.Listen.HTTPSCertFile"] = BConfig.Listen.HTTPSCertFile
|
|
|
|
m["BConfig.Listen.HTTPSKeyFile"] = BConfig.Listen.HTTPSKeyFile
|
|
|
|
m["BConfig.Listen.EnableAdmin"] = BConfig.Listen.EnableAdmin
|
|
|
|
m["BConfig.Listen.AdminAddr"] = BConfig.Listen.AdminAddr
|
|
|
|
m["BConfig.Listen.AdminPort"] = BConfig.Listen.AdminPort
|
|
|
|
m["BConfig.Listen.EnableFcgi"] = BConfig.Listen.EnableFcgi
|
|
|
|
m["BConfig.Listen.EnableStdIo"] = BConfig.Listen.EnableStdIo
|
|
|
|
m["BConfig.WebConfig.AutoRender"] = BConfig.WebConfig.AutoRender
|
|
|
|
m["BConfig.WebConfig.EnableDocs"] = BConfig.WebConfig.EnableDocs
|
|
|
|
m["BConfig.WebConfig.FlashName"] = BConfig.WebConfig.FlashName
|
|
|
|
m["BConfig.WebConfig.FlashSeparator"] = BConfig.WebConfig.FlashSeparator
|
|
|
|
m["BConfig.WebConfig.DirectoryIndex"] = BConfig.WebConfig.DirectoryIndex
|
|
|
|
m["BConfig.WebConfig.StaticDir"] = BConfig.WebConfig.StaticDir
|
|
|
|
m["BConfig.WebConfig.StaticExtensionsToGzip"] = BConfig.WebConfig.StaticExtensionsToGzip
|
2020-06-02 10:22:47 +00:00
|
|
|
m["BConfig.WebConfig.StaticCacheFileSize"] = BConfig.WebConfig.StaticCacheFileSize
|
|
|
|
m["BConfig.WebConfig.StaticCacheFileNum"] = BConfig.WebConfig.StaticCacheFileNum
|
2016-04-18 11:16:39 +00:00
|
|
|
m["BConfig.WebConfig.TemplateLeft"] = BConfig.WebConfig.TemplateLeft
|
|
|
|
m["BConfig.WebConfig.TemplateRight"] = BConfig.WebConfig.TemplateRight
|
|
|
|
m["BConfig.WebConfig.ViewsPath"] = BConfig.WebConfig.ViewsPath
|
|
|
|
m["BConfig.WebConfig.EnableXSRF"] = BConfig.WebConfig.EnableXSRF
|
|
|
|
m["BConfig.WebConfig.XSRFExpire"] = BConfig.WebConfig.XSRFExpire
|
|
|
|
m["BConfig.WebConfig.Session.SessionOn"] = BConfig.WebConfig.Session.SessionOn
|
|
|
|
m["BConfig.WebConfig.Session.SessionProvider"] = BConfig.WebConfig.Session.SessionProvider
|
|
|
|
m["BConfig.WebConfig.Session.SessionName"] = BConfig.WebConfig.Session.SessionName
|
|
|
|
m["BConfig.WebConfig.Session.SessionGCMaxLifetime"] = BConfig.WebConfig.Session.SessionGCMaxLifetime
|
|
|
|
m["BConfig.WebConfig.Session.SessionProviderConfig"] = BConfig.WebConfig.Session.SessionProviderConfig
|
|
|
|
m["BConfig.WebConfig.Session.SessionCookieLifeTime"] = BConfig.WebConfig.Session.SessionCookieLifeTime
|
|
|
|
m["BConfig.WebConfig.Session.SessionAutoSetCookie"] = BConfig.WebConfig.Session.SessionAutoSetCookie
|
|
|
|
m["BConfig.WebConfig.Session.SessionDomain"] = BConfig.WebConfig.Session.SessionDomain
|
2016-10-11 16:06:22 +00:00
|
|
|
m["BConfig.WebConfig.Session.SessionDisableHTTPOnly"] = BConfig.WebConfig.Session.SessionDisableHTTPOnly
|
2016-04-18 11:16:39 +00:00
|
|
|
m["BConfig.Log.AccessLogs"] = BConfig.Log.AccessLogs
|
2018-04-28 18:03:39 +00:00
|
|
|
m["BConfig.Log.EnableStaticLogs"] = BConfig.Log.EnableStaticLogs
|
2017-09-13 00:03:46 +00:00
|
|
|
m["BConfig.Log.AccessLogsFormat"] = BConfig.Log.AccessLogsFormat
|
2016-04-18 11:16:39 +00:00
|
|
|
m["BConfig.Log.FileLineNum"] = BConfig.Log.FileLineNum
|
|
|
|
m["BConfig.Log.Outputs"] = BConfig.Log.Outputs
|
|
|
|
return m
|
|
|
|
}
|
2020-07-06 15:04:29 +00:00
|
|
|
|
|
|
|
func TestExecJSON(t *testing.T) {
|
|
|
|
t.Log("Testing the adding of JSON to the response")
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
originalBody := []int{1, 2, 3}
|
|
|
|
|
|
|
|
res, _ := json.Marshal(originalBody)
|
|
|
|
|
|
|
|
execJSON(w, res)
|
|
|
|
|
|
|
|
decodedBody := []int{}
|
|
|
|
err := json.NewDecoder(w.Body).Decode(&decodedBody)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Should be able to decode response body into decodedBody slice")
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range decodedBody {
|
|
|
|
if decodedBody[i] != originalBody[i] {
|
|
|
|
t.Fatalf("Expected %d but got %d in decoded body slice", originalBody[i], decodedBody[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|