v2ray-core/common/errors/errors_test.go

50 lines
965 B
Go
Raw Normal View History

2017-02-21 22:14:07 +00:00
package errors_test
import (
"io"
"testing"
. "v2ray.com/core/common/errors"
2017-10-24 14:15:35 +00:00
. "v2ray.com/ext/assert"
2017-02-21 22:14:07 +00:00
)
2017-04-06 19:13:17 +00:00
func TestError(t *testing.T) {
2017-10-24 14:15:35 +00:00
assert := With(t)
2017-02-21 22:14:07 +00:00
err := New("TestError")
2017-10-24 14:15:35 +00:00
assert(GetSeverity(err), Equals, SeverityInfo)
2017-02-21 22:14:07 +00:00
2017-04-06 13:13:09 +00:00
err = New("TestError2").Base(io.EOF)
2017-10-24 14:15:35 +00:00
assert(GetSeverity(err), Equals, SeverityInfo)
2017-02-21 22:14:07 +00:00
2017-04-06 13:13:09 +00:00
err = New("TestError3").Base(io.EOF).AtWarning()
2017-10-24 14:15:35 +00:00
assert(GetSeverity(err), Equals, SeverityWarning)
2017-02-21 22:14:07 +00:00
2017-04-06 13:13:09 +00:00
err = New("TestError4").Base(io.EOF).AtWarning()
err = New("TestError5").Base(err)
2017-10-24 14:15:35 +00:00
assert(GetSeverity(err), Equals, SeverityWarning)
assert(err.Error(), HasSubstring, "EOF")
2017-02-21 22:14:07 +00:00
}
2017-04-06 19:13:17 +00:00
func TestErrorMessage(t *testing.T) {
2017-10-24 14:15:35 +00:00
assert := With(t)
2017-04-06 19:13:17 +00:00
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 {
2017-10-24 14:15:35 +00:00
assert(d.err.Error(), Equals, d.msg)
2017-04-06 19:13:17 +00:00
}
}