forked from contiv/netplugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
45 lines (35 loc) · 998 Bytes
/
error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package core
import (
"fmt"
"strings"
"testing"
)
func TestErrorStringFormat(t *testing.T) {
refStr := "error string"
e := Errorf("%s", refStr)
fileName := "error_test.go"
lineNum := 11 // line number where error was formed
funcName := "github.com/contiv/netplugin/core.TestErrorStringFormat"
expectedStr := fmt.Sprintf("%s [%s %d]", funcName, fileName, lineNum)
if errMsg := strings.Split(e.Error(), "\n"); errMsg[0] != refStr || errMsg[1] != expectedStr {
t.Fatalf("error string mismatch. Expected: %q, got %q", expectedStr,
e.Error())
}
}
func getError(msg string) *Error {
return Errorf(msg)
}
func TestErrorStackTrace(t *testing.T) {
msg := "an error"
e := getError(msg)
if e.desc != msg {
t.Fatal("Description did not match provided")
}
if e.Error() == "an error\n" {
t.Fatal("Error message did not yield stack trace")
}
lines := strings.Split(e.Error(), "\n")
if len(lines) != 6 {
t.Fatalf("Stack trace yielded incorrect count: %d", len(lines))
}
}