1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/common/errors/errors_test.go
Darien Raymond 24288a74a2
update tests
2018-11-15 11:17:20 +01:00

55 lines
1.1 KiB
Go

package errors_test
import (
"io"
"testing"
"github.com/google/go-cmp/cmp"
. "v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
. "v2ray.com/ext/assert"
)
func TestError(t *testing.T) {
assert := With(t)
err := New("TestError")
assert(GetSeverity(err), Equals, log.Severity_Info)
err = New("TestError2").Base(io.EOF)
assert(GetSeverity(err), Equals, log.Severity_Info)
err = New("TestError3").Base(io.EOF).AtWarning()
assert(GetSeverity(err), Equals, log.Severity_Warning)
err = New("TestError4").Base(io.EOF).AtWarning()
err = New("TestError5").Base(err)
assert(GetSeverity(err), Equals, log.Severity_Warning)
assert(err.Error(), HasSubstring, "EOF")
}
type e struct{}
func TestErrorMessage(t *testing.T) {
data := []struct {
err error
msg string
}{
{
err: New("a").Base(New("b")).WithPathObj(e{}),
msg: "v2ray.com/core/common/errors_test: a > b",
},
{
err: New("a").Base(New("b").WithPathObj(e{})),
msg: "a > v2ray.com/core/common/errors_test: b",
},
}
for _, d := range data {
if diff := cmp.Diff(d.msg, d.err.Error()); diff != "" {
t.Error(diff)
}
}
}