This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
errors_test.go
71 lines (58 loc) · 1.52 KB
/
errors_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package servicebus
import (
"errors"
"fmt"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestErrMissingField_Error(t *testing.T) {
const fieldName = "fieldName"
var subject ErrMissingField = fieldName
var cast error = subject
got := cast.Error()
const want = `missing value "` + fieldName + `"`
if got != want {
t.Logf("\n\tgot: \t%q\n\twant:\t%q", got, want)
t.Fail()
}
}
func TestErrIncorrectType_Error(t *testing.T) {
var a int
var b map[string]interface{}
var c *float64
types := map[reflect.Type]interface{}{
reflect.TypeOf(a): 7.0,
reflect.TypeOf(b): map[string]string{},
reflect.TypeOf(c): int(2),
}
const key = "myFieldName"
for expected, actual := range types {
actualType := reflect.TypeOf(actual)
t.Run(fmt.Sprintf("%s-%s", expected, actualType), func(t *testing.T) {
expectedMessage := fmt.Sprintf(
"value at %q was expected to be of type %q but was actually of type %q",
key,
expected.String(),
actualType.String())
subject := ErrIncorrectType{
Key: key,
ActualValue: actual,
ExpectedType: expected,
}
var cast error = subject
got := cast.Error()
if got != expectedMessage {
t.Logf("\n\tgot: \t%q\n\twant:\t%q", got, expectedMessage)
t.Fail()
}
})
}
}
func TestErrNotFound_Error(t *testing.T) {
err := ErrNotFound{EntityPath: "/foo/bar"}
assert.Equal(t, "entity at /foo/bar not found", err.Error())
assert.True(t, IsErrNotFound(err))
otherErr := errors.New("foo")
assert.False(t, IsErrNotFound(otherErr))
}