1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/common/errors/errors_test.go

52 lines
1.1 KiB
Go
Raw Normal View History

2017-02-21 17:14:07 -05:00
package errors_test
import (
"io"
"testing"
2018-07-13 08:36:09 -04:00
"v2ray.com/core/common/compare"
2017-02-21 17:14:07 -05:00
. "v2ray.com/core/common/errors"
2017-12-10 17:33:23 -05:00
"v2ray.com/core/common/log"
2017-10-24 10:15:35 -04:00
. "v2ray.com/ext/assert"
2017-02-21 17:14:07 -05:00
)
2017-04-06 15:13:17 -04:00
func TestError(t *testing.T) {
2017-10-24 10:15:35 -04:00
assert := With(t)
2017-02-21 17:14:07 -05:00
err := New("TestError")
2017-12-10 17:33:23 -05:00
assert(GetSeverity(err), Equals, log.Severity_Info)
2017-02-21 17:14:07 -05:00
2017-04-06 09:13:09 -04:00
err = New("TestError2").Base(io.EOF)
2017-12-10 17:33:23 -05:00
assert(GetSeverity(err), Equals, log.Severity_Info)
2017-02-21 17:14:07 -05:00
2017-04-06 09:13:09 -04:00
err = New("TestError3").Base(io.EOF).AtWarning()
2017-12-10 17:33:23 -05:00
assert(GetSeverity(err), Equals, log.Severity_Warning)
2017-02-21 17:14:07 -05:00
2017-04-06 09:13:09 -04:00
err = New("TestError4").Base(io.EOF).AtWarning()
err = New("TestError5").Base(err)
2017-12-10 17:33:23 -05:00
assert(GetSeverity(err), Equals, log.Severity_Warning)
2017-10-24 10:15:35 -04:00
assert(err.Error(), HasSubstring, "EOF")
2017-02-21 17:14:07 -05:00
}
2017-04-06 15:13:17 -04:00
func TestErrorMessage(t *testing.T) {
data := []struct {
err error
msg string
}{
{
err: New("a").Base(New("b")).Path("c", "d", "e"),
msg: "c|d|e: a > b",
},
{
err: New("a").Base(New("b").Path("c")).Path("d", "e"),
msg: "d|e: a > c: b",
},
}
for _, d := range data {
2018-07-13 08:36:09 -04:00
if err := compare.StringEqualWithDetail(d.msg, d.err.Error()); err != nil {
t.Fatal(err)
}
2017-04-06 15:13:17 -04:00
}
}