| 1 | package krberror |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/stretchr/testify/assert" |
| 8 | ) |
| 9 | |
| 10 | func TestErrorf(t *testing.T) { |
| 11 | err := fmt.Errorf("an error") |
| 12 | var a Krberror |
| 13 | a = Errorf(err, "cause", "some text") |
| 14 | assert.Equal(t, "[Root cause: cause] cause: some text: an error", a.Error()) |
| 15 | a = Errorf(err, "cause", "arg1=%d arg2=%s", 123, "arg") |
| 16 | assert.Equal(t, "[Root cause: cause] cause: arg1=123 arg2=arg: an error", a.Error()) |
| 17 | |
| 18 | err = NewErrorf("another error", "some text") |
| 19 | a = Errorf(err, "cause", "some text") |
| 20 | assert.Equal(t, "[Root cause: another error] cause: some text < another error: some text", a.Error()) |
| 21 | a = Errorf(err, "cause", "arg1=%d arg2=%s", 123, "arg") |
| 22 | assert.Equal(t, "[Root cause: another error] cause: arg1=123 arg2=arg < another error: some text", a.Error()) |
| 23 | } |