-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
private_test.go
50 lines (38 loc) · 1.1 KB
/
private_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
package errors
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
type stringError string
func (e *stringError) Error() string {
return string(*e)
}
type structError struct {
Foo string `json:"foo"`
}
func (s *structError) Error() string {
return s.Foo
}
type structParentError struct {
structError
}
type structWithMarshalerError struct{}
func (s structWithMarshalerError) MarshalJSON() ([]byte, error) {
return []byte(`{"error":"test"}`), nil
}
func (s *structWithMarshalerError) Error() string {
return "test"
}
func TestUseMarshaler(t *testing.T) {
t.Parallel()
assert.False(t, useMarshaler(New("test")))
assert.False(t, useMarshaler(&fundamentalError{})) //nolint:exhaustruct
assert.False(t, useMarshaler(Base("test")))
assert.True(t, useMarshaler(&structWithMarshalerError{}))
var se stringError = "test"
assert.False(t, useMarshaler(&se))
assert.False(t, useMarshaler(&json.MarshalerError{})) //nolint:exhaustruct
assert.True(t, useMarshaler(&structError{})) //nolint:exhaustruct
assert.True(t, useMarshaler(&structParentError{})) //nolint:exhaustruct
}