base_test.go
1022 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package controllers
import (
"fmt"
"log"
"reflect"
"testing"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
)
func Test_GenMessage(t *testing.T){
input := []struct {
Rsp interface{}
Error error
Exceprt *mybeego.Message
}{
{Rsp:"test",Error:fmt.Errorf("test"),Exceprt:mybeego.NewMessage(1)},
{Rsp:"test-A",Error:common.NewErrorWithMsg(100,"test-A"),Exceprt:mybeego.NewErrMessage(100,"test-A")},
}
for i:=range input{
o :=input[i]
out :=DefaultController.GenMessage(o.Rsp,o.Error)
if !reflect.DeepEqual(out,o.Exceprt){
log.Fatal("not equal ",out,o.Exceprt)
}
}
}
func Benchmark_GenMessage(b *testing.B) {
o := struct {
Rsp interface{}
Error error
Exceprt *mybeego.Message
}{Rsp:"test",Error:fmt.Errorf("test"),Exceprt:mybeego.NewMessage(1)}
for i:=0;i<b.N;i++{
out :=DefaultController.GenMessage(o.Rsp,o.Error)
if out.Errmsg!=o.Exceprt.Errmsg || out.Errno!=o.Exceprt.Errno{
log.Fatal("not equal ",out,o.Exceprt)
}
}
}