From 805e57cf3fb2a8e05d618757ebb0167484fb4c52 Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Thu, 6 Apr 2017 17:52:43 +0800 Subject: [PATCH 01/12] add dotweb_Test --- dotweb.go | 15 ++++++++------- dotweb_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 dotweb_test.go diff --git a/dotweb.go b/dotweb.go index 48d6b36..b5f1e05 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..bc400df --- /dev/null +++ b/dotweb_test.go @@ -0,0 +1,26 @@ +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) + } +} From 12a3d0ddcd973e84a66e558211bc21357f5a71ee Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Thu, 6 Apr 2017 18:08:14 +0800 Subject: [PATCH 02/12] update dotweb_test file --- dotweb_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dotweb_test.go b/dotweb_test.go index bc400df..bcee5ae 100644 --- a/dotweb_test.go +++ b/dotweb_test.go @@ -24,3 +24,20 @@ func Test_RunMode_2(t *testing.T) { 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) +} + +// From 65368300fafd90dda70f40d02d76400b996662ee Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Fri, 7 Apr 2017 09:22:09 +0800 Subject: [PATCH 03/12] add Unit test files --- .gitignore | 3 +++ state_test.go | 24 ++++++++++++++++++++++++ uploadfile_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 .gitignore create mode 100644 state_test.go create mode 100644 uploadfile_test.go 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/state_test.go b/state_test.go new file mode 100644 index 0000000..9730493 --- /dev/null +++ b/state_test.go @@ -0,0 +1,24 @@ +package dotweb + +import ( + "testing" +) + +// 以下为功能测试 + +func Test_AddRequestCount_1(t *testing.T) { + var num uint64 = 0 + for i := 1; i < 100; i++ { + num = GlobalState.AddRequestCount(uint64(i)) + } + t.Log("TotalRequestCount:", num) + +} + +func Test_AddErrorCount_1(t *testing.T) { + var num uint64 = 0 + for i := 1; i < 100; i++ { + num = GlobalState.AddErrorCount(uint64(i)) + } + t.Log("TotalErrorCount:", 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) { + // +} From 4fce0c43f83b989a3dddbd9fdd271d2c3faee86a Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Fri, 7 Apr 2017 09:35:53 +0800 Subject: [PATCH 04/12] update Unit test files --- state_test.go | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/state_test.go b/state_test.go index 9730493..724615f 100644 --- a/state_test.go +++ b/state_test.go @@ -7,18 +7,40 @@ import ( // 以下为功能测试 func Test_AddRequestCount_1(t *testing.T) { - var num uint64 = 0 - for i := 1; i < 100; i++ { - num = GlobalState.AddRequestCount(uint64(i)) + var num uint64 = 1 + var count uint64 + for i := 0; i < 100; i++ { + count = GlobalState.AddRequestCount(num) } - t.Log("TotalRequestCount:", 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 uint64 = 0 - for i := 1; i < 100; i++ { - num = GlobalState.AddErrorCount(uint64(i)) + 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:", num) + t.Log("TotalErrorCount:", count) } + +// 以下是性能测试 From ee79739604112e0e7de9b87106b20e8c23acdcd4 Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Fri, 7 Apr 2017 12:56:53 +0800 Subject: [PATCH 05/12] update Unit test files --- state_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/state_test.go b/state_test.go index 724615f..8f56b09 100644 --- a/state_test.go +++ b/state_test.go @@ -44,3 +44,39 @@ func Test_AddErrorCount_2(t *testing.T) { } // 以下是性能测试 + +//基准测试 +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) + } + }) +} From 276af2aacebfc1ccbf84e74ba39f7e535dd8144c Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Fri, 7 Apr 2017 13:07:49 +0800 Subject: [PATCH 06/12] Add Utils Test File --- bind_test.go | 0 cache/cache_test.go | 1 + cache/redis/cache_redis_test.go | 1 + cache/runtime/cache_runtime_test.go | 1 + config/configs_test.go | 1 + consts_test.go | 0 context_test.go | 0 core/context_test.go | 1 + core/hideReaddirFS_test.go | 1 + hijack_test.go | 0 logger/logger_test.go | 0 logger/xlog_test.go | 0 render_test.go | 0 response_test.go | 0 router_test.go | 0 routers/path_test.go | 0 routers/router_Test.go | 0 routers/tree_test.go | 0 server_test.go | 0 servers/offlineserver_test.go | 0 servers/server_Test.go | 0 session/session_test.go | 0 session/sessionstate_test.go | 0 session/store_redis_test.go | 0 session/stoure_runtime_test.go | 0 25 files changed, 6 insertions(+) create mode 100644 bind_test.go create mode 100644 cache/cache_test.go create mode 100644 cache/redis/cache_redis_test.go create mode 100644 cache/runtime/cache_runtime_test.go create mode 100644 config/configs_test.go create mode 100644 consts_test.go create mode 100644 context_test.go create mode 100644 core/context_test.go create mode 100644 core/hideReaddirFS_test.go create mode 100644 hijack_test.go create mode 100644 logger/logger_test.go create mode 100644 logger/xlog_test.go create mode 100644 render_test.go create mode 100644 response_test.go create mode 100644 router_test.go create mode 100644 routers/path_test.go create mode 100644 routers/router_Test.go create mode 100644 routers/tree_test.go create mode 100644 server_test.go create mode 100644 servers/offlineserver_test.go create mode 100644 servers/server_Test.go create mode 100644 session/session_test.go create mode 100644 session/sessionstate_test.go create mode 100644 session/store_redis_test.go create mode 100644 session/stoure_runtime_test.go diff --git a/bind_test.go b/bind_test.go new file mode 100644 index 0000000..e69de29 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..e69de29 diff --git a/context_test.go b/context_test.go new file mode 100644 index 0000000..e69de29 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/hijack_test.go b/hijack_test.go new file mode 100644 index 0000000..e69de29 diff --git a/logger/logger_test.go b/logger/logger_test.go new file mode 100644 index 0000000..e69de29 diff --git a/logger/xlog_test.go b/logger/xlog_test.go new file mode 100644 index 0000000..e69de29 diff --git a/render_test.go b/render_test.go new file mode 100644 index 0000000..e69de29 diff --git a/response_test.go b/response_test.go new file mode 100644 index 0000000..e69de29 diff --git a/router_test.go b/router_test.go new file mode 100644 index 0000000..e69de29 diff --git a/routers/path_test.go b/routers/path_test.go new file mode 100644 index 0000000..e69de29 diff --git a/routers/router_Test.go b/routers/router_Test.go new file mode 100644 index 0000000..e69de29 diff --git a/routers/tree_test.go b/routers/tree_test.go new file mode 100644 index 0000000..e69de29 diff --git a/server_test.go b/server_test.go new file mode 100644 index 0000000..e69de29 diff --git a/servers/offlineserver_test.go b/servers/offlineserver_test.go new file mode 100644 index 0000000..e69de29 diff --git a/servers/server_Test.go b/servers/server_Test.go new file mode 100644 index 0000000..e69de29 diff --git a/session/session_test.go b/session/session_test.go new file mode 100644 index 0000000..e69de29 diff --git a/session/sessionstate_test.go b/session/sessionstate_test.go new file mode 100644 index 0000000..e69de29 diff --git a/session/store_redis_test.go b/session/store_redis_test.go new file mode 100644 index 0000000..e69de29 diff --git a/session/stoure_runtime_test.go b/session/stoure_runtime_test.go new file mode 100644 index 0000000..e69de29 From b0d8eaf10ab55f686044baf52611b7ed54205c29 Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Fri, 7 Apr 2017 13:32:11 +0800 Subject: [PATCH 07/12] add All utils test files --- bind_test.go | 1 + consts_test.go | 1 + context_test.go | 1 + framework/convert/convert_test.go | 13 +++++++++++++ framework/crypto/cryptos_test.go | 9 +++++++++ framework/crypto/des/des_test.go | 11 +++++++++++ framework/encodes/gob/gobutil_test.go | 11 +++++++++++ framework/exception/exception_test.go | 7 +++++++ framework/file/file_test.go | 1 + framework/json/jsonutil_test.go | 1 + framework/redis/redisutil_test.go | 1 + framework/reflects/reflects_test.go | 1 + hijack_test.go | 1 + logger/logger_test.go | 1 + logger/xlog_test.go | 1 + render_test.go | 1 + response_test.go | 1 + router_test.go | 1 + routers/path_test.go | 1 + routers/router_Test.go | 1 + routers/tree_test.go | 1 + server_test.go | 1 + servers/offlineserver_test.go | 1 + servers/server_Test.go | 1 + session/session_test.go | 1 + session/sessionstate_test.go | 1 + session/store_redis_test.go | 1 + session/stoure_runtime_test.go | 1 + websocket_test.go | 1 + 29 files changed, 75 insertions(+) create mode 100644 framework/convert/convert_test.go create mode 100644 framework/crypto/cryptos_test.go create mode 100644 framework/crypto/des/des_test.go create mode 100644 framework/encodes/gob/gobutil_test.go create mode 100644 framework/exception/exception_test.go create mode 100644 framework/file/file_test.go create mode 100644 framework/json/jsonutil_test.go create mode 100644 framework/redis/redisutil_test.go create mode 100644 framework/reflects/reflects_test.go create mode 100644 websocket_test.go diff --git a/bind_test.go b/bind_test.go index e69de29..9546857 100644 --- a/bind_test.go +++ b/bind_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/consts_test.go b/consts_test.go index e69de29..9546857 100644 --- a/consts_test.go +++ b/consts_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/context_test.go b/context_test.go index e69de29..9546857 100644 --- a/context_test.go +++ b/context_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/framework/convert/convert_test.go b/framework/convert/convert_test.go new file mode 100644 index 0000000..affc6cb --- /dev/null +++ b/framework/convert/convert_test.go @@ -0,0 +1,13 @@ +package convert + +import ( + "testing" +) + +//功能测试 + +func Test_String2Bytes_1(t *testing.T) { + str := "0123456789" + b := String2Bytes(str) + t.Log(str, " to byte: ", b) +} diff --git a/framework/crypto/cryptos_test.go b/framework/crypto/cryptos_test.go new file mode 100644 index 0000000..7e6e5b3 --- /dev/null +++ b/framework/crypto/cryptos_test.go @@ -0,0 +1,9 @@ +package cryptos + +import ( + "testing" +) + +// + +func Test_GetMd5String_1(t *testing.T) {} diff --git a/framework/crypto/des/des_test.go b/framework/crypto/des/des_test.go new file mode 100644 index 0000000..3d76c26 --- /dev/null +++ b/framework/crypto/des/des_test.go @@ -0,0 +1,11 @@ +package des + +import ( + "testing" +) + +// + +func Test_ECBEncrypt_1(t *testing.T) {} + +func Test_ECBDecrypt_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..fafb4df --- /dev/null +++ b/framework/exception/exception_test.go @@ -0,0 +1,7 @@ +package exception + +import ( + "testing" +) + +func Test_CatchError_1(t *testing.T) {} diff --git a/framework/file/file_test.go b/framework/file/file_test.go new file mode 100644 index 0000000..b691ba5 --- /dev/null +++ b/framework/file/file_test.go @@ -0,0 +1 @@ +package file 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 index e69de29..9546857 100644 --- a/hijack_test.go +++ b/hijack_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/logger/logger_test.go b/logger/logger_test.go index e69de29..90c66f6 100644 --- a/logger/logger_test.go +++ b/logger/logger_test.go @@ -0,0 +1 @@ +package logger diff --git a/logger/xlog_test.go b/logger/xlog_test.go index e69de29..90c66f6 100644 --- a/logger/xlog_test.go +++ b/logger/xlog_test.go @@ -0,0 +1 @@ +package logger diff --git a/render_test.go b/render_test.go index e69de29..9546857 100644 --- a/render_test.go +++ b/render_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/response_test.go b/response_test.go index e69de29..9546857 100644 --- a/response_test.go +++ b/response_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/router_test.go b/router_test.go index e69de29..9546857 100644 --- a/router_test.go +++ b/router_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/routers/path_test.go b/routers/path_test.go index e69de29..159906f 100644 --- a/routers/path_test.go +++ b/routers/path_test.go @@ -0,0 +1 @@ +package routers diff --git a/routers/router_Test.go b/routers/router_Test.go index e69de29..159906f 100644 --- a/routers/router_Test.go +++ b/routers/router_Test.go @@ -0,0 +1 @@ +package routers diff --git a/routers/tree_test.go b/routers/tree_test.go index e69de29..159906f 100644 --- a/routers/tree_test.go +++ b/routers/tree_test.go @@ -0,0 +1 @@ +package routers diff --git a/server_test.go b/server_test.go index e69de29..9546857 100644 --- a/server_test.go +++ b/server_test.go @@ -0,0 +1 @@ +package dotweb diff --git a/servers/offlineserver_test.go b/servers/offlineserver_test.go index e69de29..84c4cc0 100644 --- a/servers/offlineserver_test.go +++ b/servers/offlineserver_test.go @@ -0,0 +1 @@ +package servers diff --git a/servers/server_Test.go b/servers/server_Test.go index e69de29..84c4cc0 100644 --- a/servers/server_Test.go +++ b/servers/server_Test.go @@ -0,0 +1 @@ +package servers diff --git a/session/session_test.go b/session/session_test.go index e69de29..ab87616 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -0,0 +1 @@ +package session diff --git a/session/sessionstate_test.go b/session/sessionstate_test.go index e69de29..ab87616 100644 --- a/session/sessionstate_test.go +++ b/session/sessionstate_test.go @@ -0,0 +1 @@ +package session diff --git a/session/store_redis_test.go b/session/store_redis_test.go index e69de29..ab87616 100644 --- a/session/store_redis_test.go +++ 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 index e69de29..ab87616 100644 --- a/session/stoure_runtime_test.go +++ b/session/stoure_runtime_test.go @@ -0,0 +1 @@ +package session 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 From 995f626e5657da44a00e776c1159e76f336ef883 Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Fri, 7 Apr 2017 13:55:14 +0800 Subject: [PATCH 08/12] modified convert pkg Test --- framework/convert/convert_test.go | 68 ++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/framework/convert/convert_test.go b/framework/convert/convert_test.go index affc6cb..ed80d4a 100644 --- a/framework/convert/convert_test.go +++ b/framework/convert/convert_test.go @@ -2,6 +2,7 @@ package convert import ( "testing" + "time" ) //功能测试 @@ -9,5 +10,70 @@ import ( func Test_String2Bytes_1(t *testing.T) { str := "0123456789" b := String2Bytes(str) - t.Log(str, " to byte: ", b) + t.Log(str, " String to Byte: ", b) +} + +func Test_String2Int_1(t *testing.T) { + str := "1234567890" + b, e := String2Int(str) + t.Error(e) + t.Log(str, " String to Int: ", b) +} + +func Test_String2Int_2(t *testing.T) { + str := "1234567890ssss" + b, e := String2Int(str) + t.Error(e) + t.Log(str, " String to Int: ", b) +} + +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) + t.Error(e) + t.Log(str, "String to Int64: ", b) +} + +//String2Int64 +func Test_String2Int64_2(t *testing.T) { + str := "a0200000010" + b, e := String2Int64(str) + t.Error(e) + 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) + t.Error(e) + t.Log(now, "NSToTime: ", b) +} + +//NSToTime +func Test_NSToTime_2(t *testing.T) { + now := time.Now().Unix() + b, e := NSToTime(now) + t.Error(e) + t.Log(now, "NSToTime: ", b) } From f85413a0e4c86f4d913b039ce9c17d00c2e3a7a3 Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Fri, 7 Apr 2017 14:07:15 +0800 Subject: [PATCH 09/12] modified convert pkg Test --- framework/crypto/cryptos_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/framework/crypto/cryptos_test.go b/framework/crypto/cryptos_test.go index 7e6e5b3..5b896d9 100644 --- a/framework/crypto/cryptos_test.go +++ b/framework/crypto/cryptos_test.go @@ -6,4 +6,23 @@ import ( // -func Test_GetMd5String_1(t *testing.T) {} +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) + t.Log("GetRandString: length-", i, "randStr-", randStr) + if len(randStr) != i { + t.Error("GetRandString: length:", i, "randStr-len:", len(randStr)) + } + } +} From ed99d2d35307bbb270f4447cae6d8f8944579053 Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Fri, 7 Apr 2017 17:49:00 +0800 Subject: [PATCH 10/12] add unit test of framework's modules --- framework/convert/convert_test.go | 36 +++++++++++++++++++-------- framework/crypto/cryptos_test.go | 3 ++- framework/crypto/des/des_test.go | 30 ++++++++++++++++++++-- framework/exception/exception_test.go | 9 ++++++- 4 files changed, 64 insertions(+), 14 deletions(-) diff --git a/framework/convert/convert_test.go b/framework/convert/convert_test.go index ed80d4a..0d92289 100644 --- a/framework/convert/convert_test.go +++ b/framework/convert/convert_test.go @@ -16,15 +16,21 @@ func Test_String2Bytes_1(t *testing.T) { func Test_String2Int_1(t *testing.T) { str := "1234567890" b, e := String2Int(str) - t.Error(e) - t.Log(str, " String to Int: ", b) + 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) - t.Error(e) - t.Log(str, " String to Int: ", b) + if e == nil { + t.Log(str, " String to Int: ", b) + } else { + t.Error(e) + } } func Test_Int2String_1(t *testing.T) { @@ -37,16 +43,22 @@ func Test_Int2String_1(t *testing.T) { func Test_String2Int64_1(t *testing.T) { str := "0200000010" b, e := String2Int64(str) - t.Error(e) - t.Log(str, "String to Int64: ", b) + 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) - t.Error(e) - t.Log(str, "String to Int64: ", b) + if e != nil { + t.Error(e) + } else { + t.Log(str, "String to Int64: ", b) + } } //Int642String @@ -66,7 +78,9 @@ func Test_Int642String_2(t *testing.T) { func Test_NSToTime_1(t *testing.T) { now := time.Now().UnixNano() b, e := NSToTime(now) - t.Error(e) + if e != nil { + t.Error(e) + } t.Log(now, "NSToTime: ", b) } @@ -74,6 +88,8 @@ func Test_NSToTime_1(t *testing.T) { func Test_NSToTime_2(t *testing.T) { now := time.Now().Unix() b, e := NSToTime(now) - t.Error(e) + 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 index 5b896d9..8114d43 100644 --- a/framework/crypto/cryptos_test.go +++ b/framework/crypto/cryptos_test.go @@ -20,9 +20,10 @@ func Test_GetUUID_1(t *testing.T) { func Test_GetRandString_1(t *testing.T) { for i := 4; i < 9; i++ { randStr := GetRandString(i) - t.Log("GetRandString: length-", i, "randStr-", randStr) 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 index 3d76c26..46d3c4f 100644 --- a/framework/crypto/des/des_test.go +++ b/framework/crypto/des/des_test.go @@ -6,6 +6,32 @@ import ( // -func Test_ECBEncrypt_1(t *testing.T) {} +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) {} +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/exception/exception_test.go b/framework/exception/exception_test.go index fafb4df..b915394 100644 --- a/framework/exception/exception_test.go +++ b/framework/exception/exception_test.go @@ -1,7 +1,14 @@ package exception import ( + "errors" "testing" + + "github.com/devfeel/dotweb" ) -func Test_CatchError_1(t *testing.T) {} +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) +} From b8f2a3c11d6056fb18ba3442af85a7659ced95f0 Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Sat, 8 Apr 2017 15:22:35 +0800 Subject: [PATCH 11/12] update file modules unil test file --- framework/file/file_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/framework/file/file_test.go b/framework/file/file_test.go index b691ba5..d055527 100644 --- a/framework/file/file_test.go +++ b/framework/file/file_test.go @@ -1 +1,17 @@ package file + +import ( + "testing" +) + +// 以下是功能测试 + +func Test_GetCurrentDirectory_1(t *testing.T) { + +} + +func Test_GetFileExt_1(t *testing.T) {} + +func Test_Exist_1(t *testing.T) {} + +// 以下是性能测试 From 7021922d2cd3a71060c4982d219c1dbb54dae01f Mon Sep 17 00:00:00 2001 From: cnphpbb Date: Sat, 8 Apr 2017 15:35:18 +0800 Subject: [PATCH 12/12] update file modules unil test file --- framework/file/file_test.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/framework/file/file_test.go b/framework/file/file_test.go index d055527..6e37a8b 100644 --- a/framework/file/file_test.go +++ b/framework/file/file_test.go @@ -7,10 +7,29 @@ import ( // 以下是功能测试 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_1(t *testing.T) {} +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) {}