base_test.go 1.3 KB
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)
		}
	}
}