github.com/aquayi/gokit@v0.0.0-20170805152833-88827a405d9b/err_test.go (about)

     1  package GoKit
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func Test_Err(t *testing.T) {
    11  	err := errors.New("bar")
    12  
    13  	// 检查 Err
    14  	e := Err(err, "foo")
    15  	assert.Equal(t, e.Info, "foo", "Error.Info 不相等")
    16  	assert.Equal(t, e.Prev, err, "Error.Prev 不相等")
    17  
    18  	// 检查 输出
    19  	e = Err(e, "more")
    20  	expected := "more ==> foo ==> bar"
    21  	actual := e.Error()
    22  
    23  	assert.Equal(t, expected, actual, "格式输出出错")
    24  
    25  	// 检查 第一个 error 是 *Error 的情况
    26  	e = Err(nil, "bar")
    27  	e = Err(e, "foo")
    28  	e = Err(e, "more")
    29  
    30  	expected = "more ==> foo ==> bar"
    31  	actual = e.Error()
    32  
    33  	assert.Equal(t, expected, actual, "格式输出出错")
    34  
    35  }