-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror_test.go
More file actions
33 lines (27 loc) · 989 Bytes
/
error_test.go
File metadata and controls
33 lines (27 loc) · 989 Bytes
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
package gokick_test
import (
"testing"
"github.com/scorfly/gokick"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewError(t *testing.T) {
t.Run("without description", func(t *testing.T) {
err := gokick.NewError(401, "not authorized")
var kickError gokick.Error
require.ErrorAs(t, err, &kickError)
assert.Equal(t, 401, kickError.Code())
assert.Equal(t, "not authorized", kickError.Message())
assert.Empty(t, kickError.Description())
assert.EqualError(t, err, "Error 401: not authorized")
})
t.Run("with description", func(t *testing.T) {
err := gokick.NewError(401, "not authorized").WithDescription("invalid scope")
var kickError gokick.Error
require.ErrorAs(t, err, &kickError)
assert.Equal(t, 401, kickError.Code())
assert.Equal(t, "not authorized", kickError.Message())
assert.Equal(t, "invalid scope", kickError.Description())
assert.EqualError(t, err, "Error 401: not authorized (invalid scope)")
})
}