base_test.go 1022 字节
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)
		}
	}
}