-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy patherrors_test.go
56 lines (49 loc) · 1.1 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
package stream_test
import (
"encoding/json"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
stream "github.com/GetStream/stream-go2/v8"
)
func TestErrorUnmarshal(t *testing.T) {
data := []byte(`{"code":42,"detail":"the details","duration":"10ms","exception":"boom","status_code":123}`)
var apiErr stream.APIError
err := json.Unmarshal(data, &apiErr)
assert.NoError(t, err)
expected := stream.APIError{
Code: 42,
Detail: "the details",
Duration: stream.Duration{Duration: 10 * time.Millisecond},
Exception: "boom",
StatusCode: 123,
}
assert.Equal(t, expected, apiErr)
}
func TestErrorString(t *testing.T) {
apiErr := stream.APIError{Detail: "boom"}
assert.Equal(t, "boom", apiErr.Error())
}
func TestToAPIError(t *testing.T) {
testCases := []struct {
err error
match bool
}{
{
err: fmt.Errorf("this is an error"),
match: false,
},
{
err: stream.APIError{},
match: true,
},
}
for _, tc := range testCases {
err, ok := stream.ToAPIError(tc.err)
assert.Equal(t, tc.match, ok)
if ok {
assert.IsType(t, stream.APIError{}, err)
}
}
}