diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f42547 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +_test +*.out \ No newline at end of file diff --git a/bind_test.go b/bind_test.go new file mode 100644 index 0000000..9546857 --- /dev/null +++ b/bind_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/cache/cache_test.go b/cache/cache_test.go new file mode 100644 index 0000000..08bf029 --- /dev/null +++ b/cache/cache_test.go @@ -0,0 +1 @@ +package cache diff --git a/cache/redis/cache_redis_test.go b/cache/redis/cache_redis_test.go new file mode 100644 index 0000000..65a229e --- /dev/null +++ b/cache/redis/cache_redis_test.go @@ -0,0 +1 @@ +package redis diff --git a/cache/runtime/cache_runtime_test.go b/cache/runtime/cache_runtime_test.go new file mode 100644 index 0000000..7ccdf5f --- /dev/null +++ b/cache/runtime/cache_runtime_test.go @@ -0,0 +1 @@ +package runtime diff --git a/config/configs_test.go b/config/configs_test.go new file mode 100644 index 0000000..d912156 --- /dev/null +++ b/config/configs_test.go @@ -0,0 +1 @@ +package config diff --git a/consts_test.go b/consts_test.go new file mode 100644 index 0000000..9546857 --- /dev/null +++ b/consts_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/context_test.go b/context_test.go new file mode 100644 index 0000000..9546857 --- /dev/null +++ b/context_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/core/context_test.go b/core/context_test.go new file mode 100644 index 0000000..9a8bc95 --- /dev/null +++ b/core/context_test.go @@ -0,0 +1 @@ +package core diff --git a/core/hideReaddirFS_test.go b/core/hideReaddirFS_test.go new file mode 100644 index 0000000..9a8bc95 --- /dev/null +++ b/core/hideReaddirFS_test.go @@ -0,0 +1 @@ +package core diff --git a/dotweb.go b/dotweb.go index 81d1232..083fe72 100644 --- a/dotweb.go +++ b/dotweb.go @@ -2,13 +2,6 @@ package dotweb import ( "fmt" - "github.com/devfeel/dotweb/cache" - "github.com/devfeel/dotweb/config" - "github.com/devfeel/dotweb/core" - "github.com/devfeel/dotweb/framework/json" - "github.com/devfeel/dotweb/logger" - "github.com/devfeel/dotweb/servers" - "github.com/devfeel/dotweb/session" "net/http" _ "net/http/pprof" "runtime" @@ -16,6 +9,14 @@ import ( "runtime/pprof" "strconv" "strings" + + "github.com/devfeel/dotweb/cache" + "github.com/devfeel/dotweb/config" + "github.com/devfeel/dotweb/core" + "github.com/devfeel/dotweb/framework/json" + "github.com/devfeel/dotweb/logger" + "github.com/devfeel/dotweb/servers" + "github.com/devfeel/dotweb/session" ) type ( diff --git a/dotweb_test.go b/dotweb_test.go new file mode 100644 index 0000000..bcee5ae --- /dev/null +++ b/dotweb_test.go @@ -0,0 +1,43 @@ +package dotweb + +import ( + "testing" +) + +// 以下为功能测试 + +// 测试RunMode函数无配置文件时的返回值 +func Test_RunMode_1(t *testing.T) { + app := New() + runMode := app.RunMode() + t.Log("RunMode:", runMode) +} + +// 测试RunMode函数有配置文件时的返回值 +func Test_RunMode_2(t *testing.T) { + runModes := []string{"dev", "development", "prod", "production"} + + app := New() + for _, value := range runModes { + app.Config.App.RunMode = value + runMode := app.RunMode() + t.Log("runModes value:", value, "RunMode:", runMode) + } +} + +//测试IsDevelopmentMode函数 +func Test_IsDevelopmentMode_1(t *testing.T) { + app := New() + app.Config.App.RunMode = "development" + b := app.IsDevelopmentMode() + t.Log("Run IsDevelopmentMode :", b) +} + +func Test_IsDevelopmentMode_2(t *testing.T) { + app := New() + app.Config.App.RunMode = "production" + b := app.IsDevelopmentMode() + t.Log("Run IsDevelopmentMode :", b) +} + +// diff --git a/framework/convert/convert_test.go b/framework/convert/convert_test.go new file mode 100644 index 0000000..0d92289 --- /dev/null +++ b/framework/convert/convert_test.go @@ -0,0 +1,95 @@ +package convert + +import ( + "testing" + "time" +) + +//功能测试 + +func Test_String2Bytes_1(t *testing.T) { + str := "0123456789" + b := String2Bytes(str) + t.Log(str, " String to Byte: ", b) +} + +func Test_String2Int_1(t *testing.T) { + str := "1234567890" + b, e := String2Int(str) + if e == nil { + t.Log(str, " String to Int: ", b) + } else { + t.Error(e) + } +} + +func Test_String2Int_2(t *testing.T) { + str := "1234567890ssss" + b, e := String2Int(str) + if e == nil { + t.Log(str, " String to Int: ", b) + } else { + t.Error(e) + } +} + +func Test_Int2String_1(t *testing.T) { + vint := 9876543210 + s := Int2String(vint) + t.Log(vint, "Int to String: ", s) +} + +//String2Int64 +func Test_String2Int64_1(t *testing.T) { + str := "0200000010" + b, e := String2Int64(str) + if e != nil { + t.Error(e) + } else { + t.Log(str, "String to Int64: ", b) + } +} + +//String2Int64 +func Test_String2Int64_2(t *testing.T) { + str := "a0200000010" + b, e := String2Int64(str) + if e != nil { + t.Error(e) + } else { + t.Log(str, "String to Int64: ", b) + } +} + +//Int642String +func Test_Int642String_1(t *testing.T) { + var vint int64 = 1 << 62 + s := Int642String(vint) + t.Log(vint, "Int64 to String: ", s) +} + +func Test_Int642String_2(t *testing.T) { + var vint int64 = 1 << 62 >> 4 + s := Int642String(vint) + t.Log(vint, "Int64 to String: ", s) +} + +//NSToTime +func Test_NSToTime_1(t *testing.T) { + now := time.Now().UnixNano() + b, e := NSToTime(now) + if e != nil { + t.Error(e) + } + t.Log(now, "NSToTime: ", b) +} + +//NSToTime +func Test_NSToTime_2(t *testing.T) { + now := time.Now().Unix() + b, e := NSToTime(now) + if e != nil { + t.Error(e) + } + t.Log(now, "NSToTime: ", b) +} diff --git a/framework/crypto/cryptos_test.go b/framework/crypto/cryptos_test.go new file mode 100644 index 0000000..8114d43 --- /dev/null +++ b/framework/crypto/cryptos_test.go @@ -0,0 +1,29 @@ +package cryptos + +import ( + "testing" +) + +// + +func Test_GetMd5String_1(t *testing.T) { + str := "123456789" + md5str := GetMd5String(str) + t.Log("GetMd5String:", md5str) +} + +func Test_GetUUID_1(t *testing.T) { + uuid := GetUUID() + t.Log("GetUUID:", uuid) +} + +func Test_GetRandString_1(t *testing.T) { + for i := 4; i < 9; i++ { + randStr := GetRandString(i) + if len(randStr) != i { + t.Error("GetRandString: length:", i, "randStr-len:", len(randStr)) + } else { + t.Log("GetRandString: length-", i, "randStr-", randStr) + } + } +} diff --git a/framework/crypto/des/des_test.go b/framework/crypto/des/des_test.go new file mode 100644 index 0000000..46d3c4f --- /dev/null +++ b/framework/crypto/des/des_test.go @@ -0,0 +1,37 @@ +package des + +import ( + "testing" +) + +// + +func Test_ECBEncrypt_1(t *testing.T) { + key := []byte("01234567") + origData := []byte("cphpbb@hotmail.com") + b, e := ECBEncrypt(origData, key) + if e != nil { + t.Error(e) + } else { + t.Logf("%x\n", b) + } +} + +func Test_ECBDecrypt_1(t *testing.T) { + hextext := []byte("a5296e4c525693a3892bbe31e1ed630121f26338ce9aa280") + key := []byte("01234567") + b, e := ECBDecrypt(hextext, key) + if e != nil { + t.Error(e) + } else { + t.Logf("%x\n", b) + } +} + +func Test_PKCS5Padding_1(t *testing.T) {} + +func Test_PKCS5UnPadding_1(t *testing.T) {} + +func Test_TripleEcbDesDecrypt_1(t *testing.T) {} + +func Test_TripleEcbDesEncrypt_1(t *testing.T) {} diff --git a/framework/encodes/gob/gobutil_test.go b/framework/encodes/gob/gobutil_test.go new file mode 100644 index 0000000..6ef7ed8 --- /dev/null +++ b/framework/encodes/gob/gobutil_test.go @@ -0,0 +1,11 @@ +package gob + +import ( + "testing" +) + +// + +func Test_EncodeMap_1(t *testing.T) { + // +} diff --git a/framework/exception/exception_test.go b/framework/exception/exception_test.go new file mode 100644 index 0000000..b915394 --- /dev/null +++ b/framework/exception/exception_test.go @@ -0,0 +1,14 @@ +package exception + +import ( + "errors" + "testing" + + "github.com/devfeel/dotweb" +) + +func Test_CatchError_1(t *testing.T) { + err := errors.New("runtime error: slice bounds out of range.") + errMsg := CatchError("httpserver::RouterHandle", dotweb.LogTarget_HttpServer, err) + t.Log(errMsg) +} diff --git a/framework/file/file_test.go b/framework/file/file_test.go new file mode 100644 index 0000000..6e37a8b --- /dev/null +++ b/framework/file/file_test.go @@ -0,0 +1,36 @@ +package file + +import ( + "testing" +) + +// 以下是功能测试 + +func Test_GetCurrentDirectory_1(t *testing.T) { + thisDir := GetCurrentDirectory() + t.Log(thisDir) +} + +func Test_GetFileExt_1(t *testing.T) { + fn := "/download/vagrant_1.9.2.dmg" + fileExt := GetFileExt(fn) + if len(fileExt) < 1 { + t.Error("fileExt null!") + } else { + t.Log(fileExt) + } +} + +func Test_GetFileExt_2(t *testing.T) { + fn := "/download/vagrant_1" + fileExt := GetFileExt(fn) + if len(fileExt) < 1 { + t.Error("fileExt null!") + } else { + t.Log(fileExt) + } +} + +func Test_Exist_1(t *testing.T) {} + +// 以下是性能测试 diff --git a/framework/json/jsonutil_test.go b/framework/json/jsonutil_test.go new file mode 100644 index 0000000..5aa90fd --- /dev/null +++ b/framework/json/jsonutil_test.go @@ -0,0 +1 @@ +package jsonutil diff --git a/framework/redis/redisutil_test.go b/framework/redis/redisutil_test.go new file mode 100644 index 0000000..b8ac1e5 --- /dev/null +++ b/framework/redis/redisutil_test.go @@ -0,0 +1 @@ +package redisutil diff --git a/framework/reflects/reflects_test.go b/framework/reflects/reflects_test.go new file mode 100644 index 0000000..57be900 --- /dev/null +++ b/framework/reflects/reflects_test.go @@ -0,0 +1 @@ +package reflects diff --git a/hijack_test.go b/hijack_test.go new file mode 100644 index 0000000..9546857 --- /dev/null +++ b/hijack_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/logger/logger_test.go b/logger/logger_test.go new file mode 100644 index 0000000..90c66f6 --- /dev/null +++ b/logger/logger_test.go @@ -0,0 +1 @@ +package logger diff --git a/logger/xlog_test.go b/logger/xlog_test.go new file mode 100644 index 0000000..90c66f6 --- /dev/null +++ b/logger/xlog_test.go @@ -0,0 +1 @@ +package logger diff --git a/render_test.go b/render_test.go new file mode 100644 index 0000000..9546857 --- /dev/null +++ b/render_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/response_test.go b/response_test.go new file mode 100644 index 0000000..9546857 --- /dev/null +++ b/response_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/router_test.go b/router_test.go new file mode 100644 index 0000000..9546857 --- /dev/null +++ b/router_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/routers/path_test.go b/routers/path_test.go new file mode 100644 index 0000000..159906f --- /dev/null +++ b/routers/path_test.go @@ -0,0 +1 @@ +package routers diff --git a/routers/router_Test.go b/routers/router_Test.go new file mode 100644 index 0000000..159906f --- /dev/null +++ b/routers/router_Test.go @@ -0,0 +1 @@ +package routers diff --git a/routers/tree_test.go b/routers/tree_test.go new file mode 100644 index 0000000..159906f --- /dev/null +++ b/routers/tree_test.go @@ -0,0 +1 @@ +package routers diff --git a/server_test.go b/server_test.go new file mode 100644 index 0000000..9546857 --- /dev/null +++ b/server_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/servers/offlineserver_test.go b/servers/offlineserver_test.go new file mode 100644 index 0000000..84c4cc0 --- /dev/null +++ b/servers/offlineserver_test.go @@ -0,0 +1 @@ +package servers diff --git a/servers/server_Test.go b/servers/server_Test.go new file mode 100644 index 0000000..84c4cc0 --- /dev/null +++ b/servers/server_Test.go @@ -0,0 +1 @@ +package servers diff --git a/session/session_test.go b/session/session_test.go new file mode 100644 index 0000000..ab87616 --- /dev/null +++ b/session/session_test.go @@ -0,0 +1 @@ +package session diff --git a/session/sessionstate_test.go b/session/sessionstate_test.go new file mode 100644 index 0000000..ab87616 --- /dev/null +++ b/session/sessionstate_test.go @@ -0,0 +1 @@ +package session diff --git a/session/store_redis_test.go b/session/store_redis_test.go new file mode 100644 index 0000000..ab87616 --- /dev/null +++ b/session/store_redis_test.go @@ -0,0 +1 @@ +package session diff --git a/session/stoure_runtime_test.go b/session/stoure_runtime_test.go new file mode 100644 index 0000000..ab87616 --- /dev/null +++ b/session/stoure_runtime_test.go @@ -0,0 +1 @@ +package session diff --git a/state_test.go b/state_test.go new file mode 100644 index 0000000..8f56b09 --- /dev/null +++ b/state_test.go @@ -0,0 +1,82 @@ +package dotweb + +import ( + "testing" +) + +// 以下为功能测试 + +func Test_AddRequestCount_1(t *testing.T) { + var num uint64 = 1 + var count uint64 + for i := 0; i < 100; i++ { + count = GlobalState.AddRequestCount(num) + } + t.Log("TotalRequestCount:", count) +} + +func Test_AddRequestCount_2(t *testing.T) { + var num uint64 = 1 + var count uint64 + for i := 0; i < 100; i++ { + count = GlobalState.AddRequestCount(num) + num++ + } + t.Log("TotalRequestCount:", count) +} + +func Test_AddErrorCount_1(t *testing.T) { + var num, count uint64 + for i := 0; i < 100; i++ { + num = 1 + count = GlobalState.AddErrorCount(num) + } + t.Log("TotalErrorCount:", count) +} + +func Test_AddErrorCount_2(t *testing.T) { + var num, count uint64 + for i := 0; i < 100; i++ { + count = GlobalState.AddErrorCount(num) + num++ + } + t.Log("TotalErrorCount:", count) +} + +// 以下是性能测试 + +//基准测试 +func Benchmark_AddErrorCount_1(b *testing.B) { + var num uint64 = 1 + for i := 0; i < b.N; i++ { + GlobalState.AddErrorCount(num) + } +} + +// 测试并发效率 +func Benchmark_AddErrorCount_Parallel(b *testing.B) { + b.RunParallel(func(pb *testing.PB) { + var num uint64 = 1 + for pb.Next() { + GlobalState.AddErrorCount(num) + } + }) +} + +//基准测试 +func Benchmark_AddRequestCount_1(b *testing.B) { + var num uint64 = 1 + for i := 0; i < b.N; i++ { + GlobalState.AddRequestCount(num) + } +} + +// 测试并发效率 +func Benchmark_AddRequestCount_Parallel(b *testing.B) { + b.RunParallel(func(pb *testing.PB) { + var num uint64 = 1 + for pb.Next() { + GlobalState.AddRequestCount(num) + } + }) +} diff --git a/uploadfile_test.go b/uploadfile_test.go new file mode 100644 index 0000000..1530ebb --- /dev/null +++ b/uploadfile_test.go @@ -0,0 +1,40 @@ +package dotweb + +import ( + "testing" +) + +// 以下为功能测试 + +func Test_NewUploadFile_1(t *testing.T) { + // +} + +func Test_FileName_1(t *testing.T) { + // +} + +func Test_Size_1(t *testing.T) { + // +} + +func Test_SaveFile_1(t *testing.T) { + // +} + +//GetFileExt +func Test_GetFileExt_1(t *testing.T) { + // +} + +func Test_Request_1(t *testing.T) { + // +} + +func Test_SendMessage_1(t *testing.T) { + // +} + +func Test_ReadMessage_1(t *testing.T) { + // +} diff --git a/websocket_test.go b/websocket_test.go new file mode 100644 index 0000000..9546857 --- /dev/null +++ b/websocket_test.go @@ -0,0 +1 @@ +package dotweb