代码拉取完成,页面将自动刷新
// Copyright 2024 FishGoddess. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package errors
import (
"io"
"testing"
)
// go test -v -cover -count=1 -test.cpu=1 -run=^TestWrap$
func TestWrap(t *testing.T) {
testCases := []struct {
code int32
message string
}{
{code: -1000, message: "io timeout"},
{code: 1000, message: "need login"},
}
for _, testCase := range testCases {
err := Wrap(testCase.code, testCase.message)
if err.Code() != testCase.code {
t.Errorf("err.Code() %d != testCase.code %d", err.Code(), testCase.code)
}
if err.Message() != testCase.message {
t.Errorf("err.Message() %s != testCase.code %s", err.Message(), testCase.message)
}
if err.Unwrap() != nil {
t.Errorf("err.Unwrap() %+v != nil", err.Unwrap())
}
}
}
// go test -v -cover -count=1 -test.cpu=1 -run=^TestWrapWith$
func TestWrapWith(t *testing.T) {
testCases := []struct {
code int32
message string
cause error
}{
{code: -1000, message: "eof", cause: io.EOF},
{code: 1000, message: "need login"},
}
for _, testCase := range testCases {
err := Wrap(testCase.code, testCase.message).With(testCase.cause)
if err.Code() != testCase.code {
t.Errorf("err.Code() %d != testCase.code %d", err.Code(), testCase.code)
}
if err.Message() != testCase.message {
t.Errorf("err.Message() %s != testCase.code %s", err.Message(), testCase.message)
}
if err.Unwrap() != testCase.cause {
t.Errorf("err.Unwrap() %+v != testCase.code %+v", err.Unwrap(), testCase.cause)
}
}
}
// go test -v -cover -count=1 -test.cpu=1 -run=^TestErrorError$
func TestErrorError(t *testing.T) {
testCases := []struct {
code int32
message string
cause error
errorString string
}{
{code: -1000, message: "eof", cause: io.EOF, errorString: "-1000: eof (EOF)"},
{code: 1000, message: "need login", errorString: "1000: need login"},
}
for _, testCase := range testCases {
err := Wrap(testCase.code, testCase.message).With(testCase.cause)
if err.Error() != testCase.errorString {
t.Errorf("err.Error() %s != testCase.errorString %s", err.Error(), testCase.errorString)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。