-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_processor_test.go
More file actions
35 lines (31 loc) · 946 Bytes
/
error_processor_test.go
File metadata and controls
35 lines (31 loc) · 946 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
34
35
package auth_test
import (
"context"
"testing"
"github.com/go-modulus/auth"
"github.com/go-modulus/modulus/http/errhttp"
"github.com/stretchr/testify/require"
)
func TestConvertAuthTagsToHttpCode(t *testing.T) {
t.Parallel()
t.Run(
"add unauthenticated code to error", func(t *testing.T) {
t.Parallel()
err := auth.AddHttpCode()(context.Background(), auth.ErrUnauthenticated)
t.Log("When try to add unauthenticated code to error")
t.Log(" Then the error gets the meta with httpCode 401")
require.Error(t, err)
require.Equal(t, 401, errhttp.HttpCode(err))
},
)
t.Run(
"add unauthorized code to error", func(t *testing.T) {
t.Parallel()
err := auth.AddHttpCode()(context.Background(), auth.ErrUnauthorized)
t.Log("When try to add unauthorized code to error")
t.Log(" Then the error gets the meta with httpCode 403")
require.Error(t, err)
require.Equal(t, 403, errhttp.HttpCode(err))
},
)
}