base_test.go
1.3 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
package controllers
import (
"fmt"
"log"
"opp/protocol"
"reflect"
"testing"
"time"
)
func Test_GenMessage(t *testing.T) {
input := []struct {
Rsp interface{}
Error error
Exceprt *protocol.ResponseMessage
}{
{Rsp: "test", Error: fmt.Errorf("test"), Exceprt: protocol.NewErrWithMessage(1, fmt.Errorf("test")).ParseToMessage()},
{Rsp: "test-A", Error: protocol.NewErrWithMessage(100, fmt.Errorf("test-A")), Exceprt: protocol.NewErrWithMessage(100, fmt.Errorf("test-A")).ParseToMessage()},
}
for i := range input {
o := input[i]
out := protocol.NewReturnResponse(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 *protocol.ResponseMessage
}{Rsp: "test", Error: fmt.Errorf("test"), Exceprt: protocol.NewErrWithMessage(1, fmt.Errorf("test-A")).ParseToMessage()}
for i := 0; i < b.N; i++ {
out := protocol.NewReturnResponse(o.Rsp, o.Error)
if out.Errmsg != o.Exceprt.Errmsg || out.Errno != o.Exceprt.Errno {
log.Fatal("not equal ", out, o.Exceprt)
}
}
}
func Test_RandTask(t *testing.T){
time :=time.Now().Unix()
num :=1
for i:=1;i<=num;i++{
r :=time%2
if r==0{
t.Log("xh","yf",time)
}
if r==1{
t.Log("yf","xh",time)
}
}
}