github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zerror/tag_test.go (about) 1 package zerror_test 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/sohaha/zlsgo" 8 "github.com/sohaha/zlsgo/zerror" 9 ) 10 11 func TestTag(t *testing.T) { 12 tt := zlsgo.NewTest(t) 13 err := errors.New("test") 14 15 zerr := zerror.With(err, "包裹错误", zerror.WrapTag(zerror.NotFound)) 16 zerr = zerror.With(zerr, "最终错误提示", zerror.WrapTag(zerror.Unauthorized)) 17 18 tt.Equal(zerror.Unauthorized, zerror.GetTag(zerr)) 19 20 e := zerror.InvalidInput.Wrap(err, "输入无效") 21 e2 := zerror.InvalidInput.Text("输入无效") 22 tt.Equal(zerror.GetTag(e), zerror.GetTag(e2)) 23 tt.Equal(zerror.InvalidInput, zerror.GetTag(e2)) 24 25 tt.Logf("%v\n", e) 26 tt.Logf("%v\n", e2) 27 }