Skip to content

Commit fd51e8e

Browse files
committed
chore: fix unit test
1 parent 206b5a3 commit fd51e8e

File tree

7 files changed

+387
-48
lines changed

7 files changed

+387
-48
lines changed

go.mod

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@ module github.com/ardikabs/golib
22

33
go 1.18
44

5-
require github.com/stretchr/testify v1.8.0
5+
require (
6+
github.com/pkg/errors v0.9.1
7+
github.com/rs/zerolog v1.28.0
8+
github.com/spf13/viper v1.13.0
9+
github.com/stretchr/testify v1.8.0
10+
)
611

712
require (
813
github.com/davecgh/go-spew v1.1.1 // indirect
914
github.com/fsnotify/fsnotify v1.5.4 // indirect
1015
github.com/hashicorp/hcl v1.0.0 // indirect
1116
github.com/magiconair/properties v1.8.6 // indirect
17+
github.com/mattn/go-colorable v0.1.13 // indirect
18+
github.com/mattn/go-isatty v0.0.16 // indirect
1219
github.com/mitchellh/mapstructure v1.5.0 // indirect
1320
github.com/pelletier/go-toml v1.9.5 // indirect
1421
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
15-
github.com/pkg/errors v0.9.1 // indirect
1622
github.com/pmezard/go-difflib v1.0.0 // indirect
1723
github.com/spf13/afero v1.9.2 // indirect
1824
github.com/spf13/cast v1.5.0 // indirect
1925
github.com/spf13/jwalterweatherman v1.1.0 // indirect
2026
github.com/spf13/pflag v1.0.5 // indirect
21-
github.com/spf13/viper v1.13.0 // indirect
2227
github.com/subosito/gotenv v1.4.1 // indirect
23-
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect
28+
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
2429
golang.org/x/text v0.3.7 // indirect
2530
gopkg.in/ini.v1 v1.67.0 // indirect
2631
gopkg.in/yaml.v2 v2.4.0 // indirect

go.sum

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
4646
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
4747
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
4848
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
49+
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
4950
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5051
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5152
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -55,11 +56,13 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
5556
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
5657
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
5758
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
59+
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
5860
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
5961
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
6062
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
6163
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
6264
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
65+
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
6366
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
6467
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
6568
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -96,6 +99,7 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
9699
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
97100
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
98101
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
102+
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
99103
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
100104
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
101105
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -125,10 +129,18 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
125129
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
126130
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
127131
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
132+
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
128133
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
129134
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
135+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
130136
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
131137
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
138+
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
139+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
140+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
141+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
142+
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
143+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
132144
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
133145
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
134146
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
@@ -142,6 +154,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
142154
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
143155
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
144156
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
157+
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
158+
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
159+
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
160+
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
145161
github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw=
146162
github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
147163
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
@@ -297,9 +313,12 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
297313
golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
298314
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
299315
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
316+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
317+
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
300318
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
301-
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc=
302-
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
319+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
320+
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
321+
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
303322
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
304323
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
305324
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -451,7 +470,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
451470
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
452471
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
453472
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
454-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
455473
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
456474
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
457475
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

pkg/errs/errs.go

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package errs
22

33
import (
4-
"bytes"
54
"fmt"
65
"runtime"
7-
"strings"
86

97
errs "errors"
108

@@ -23,6 +21,11 @@ type Code string
2321
// Parameter represents the parameter related to the error.
2422
type Parameter string
2523

24+
// Realm is a description of a protected area, used in the WWW-Authenticate header.
25+
// Realm should be set when error Kind is Unauthenticated. If left unset, Realm
26+
// will be set to the default set by the "restricted" method
27+
type Realm string
28+
2629
// Error is the type that implements the error interface.
2730
// It contains a number of fields, each of different type.
2831
// An Error value may leave some values unset.
@@ -40,6 +43,9 @@ type Error struct {
4043
// Param represents the parameter related to the error.
4144
Param Parameter
4245

46+
// Realm is a description of a protected area, used in the WWW-Authenticate header.
47+
Realm Realm
48+
4349
// The underlying error that triggered this one, if any.
4450
Err error
4551
}
@@ -79,39 +85,32 @@ func (e Error) StackTrace() errors.StackTrace {
7985
return nil
8086
}
8187

82-
type ValidationErrors []error
83-
84-
func (v *ValidationErrors) Append(args ...interface{}) {
85-
*v = append(*v, E(args...))
86-
}
87-
88-
func (v ValidationErrors) Error() string {
89-
buff := bytes.NewBufferString("")
90-
91-
for i := 0; i < len(v); i++ {
92-
93-
if err, ok := v[i].(*Error); ok {
94-
buff.WriteString(fmt.Sprintf("%s: %s", err.Param, err.Error()))
95-
buff.WriteString("\n")
96-
}
97-
}
98-
99-
return strings.TrimSpace(buff.String())
88+
func (e *Error) isZero() bool {
89+
return e.Err == nil &&
90+
e.User == "" &&
91+
e.Param == "" &&
92+
e.Code == ""
10093
}
10194

10295
const (
103-
Other Kind = iota // Unclassified error. This value is not printed in the error message.
104-
IO // External I/O error such as network failure
105-
Private // Information withheld
106-
Internal // Internal error or inconsistency
107-
Database // Database error
108-
Exist // Resource already exist
109-
NotExist // Resource does not exists
110-
Invalid // Invalid operation for this type of item
111-
Validation // Input validation error
112-
InvalidRequest // Invalid request
113-
Permission // Permission error request
114-
Unauthenticated // Unauthenticated error if unauthenticated request occur
96+
Other Kind = iota // Unclassified error. This value is not printed in the error message.
97+
IO // External I/O error such as network failure
98+
Private // Information withheld
99+
Internal // Internal error or inconsistency
100+
Database // Database error
101+
Exist // Resource already exist
102+
NotExist // Resource does not exists
103+
Invalid // Invalid operation for this type of item
104+
Validation // Input validation error
105+
InvalidRequest // Invalid request
106+
107+
// Unauthenticated error will response with http.StatusUnauthorized (401) with empty body
108+
Unauthenticated
109+
110+
// Unauthorized error will response with http.StatusForbidden (403) with empty body
111+
// It is used when an authenticated user trying to access the resource
112+
// but not permitted to do so
113+
Unauthorized
115114
)
116115

117116
func (k Kind) String() string {
@@ -136,15 +135,17 @@ func (k Kind) String() string {
136135
return "input_validation_error"
137136
case InvalidRequest:
138137
return "invalid_request_error"
139-
case Permission:
140-
return "permission_denied"
141138
case Unauthenticated:
142139
return "unauthenticated_request"
140+
case Unauthorized:
141+
return "unauthorized_request"
143142
}
144143

145144
return "unknown_error"
146145
}
147146

147+
var DefaultRealm Realm = "restricted"
148+
148149
// E builds an error value from its arguments.
149150
// There must be at least one argument or E panics.
150151
// The type of each argument determines its meaning.
@@ -187,6 +188,8 @@ func E(args ...interface{}) error {
187188
e.Code = arg
188189
case Parameter:
189190
e.Param = arg
191+
case Realm:
192+
e.Realm = arg
190193
case string:
191194
e.Err = errors.New(arg)
192195
case *Error:
@@ -207,12 +210,19 @@ func E(args ...interface{}) error {
207210
} else {
208211
e.Err = errors.WithStack(arg)
209212
}
213+
210214
default:
211215
_, file, line, _ := runtime.Caller(1)
212216
return fmt.Errorf("errs.E: bad call from %s:%d: %v, unknown type %T, value %v in error call", file, line, args, arg, arg)
213217
}
214218
}
215219

220+
// If this error and the inner still has Realm == "", while error Kind is Unauthenticated
221+
// then the realm set to default "restricted" method
222+
if e.Realm == "" && e.Kind == Unauthenticated {
223+
e.Realm = "restricted"
224+
}
225+
216226
prev, ok := e.Err.(*Error)
217227
if !ok {
218228
return e
@@ -241,6 +251,16 @@ func E(args ...interface{}) error {
241251
prev.Param = ""
242252
}
243253

254+
if prev.Realm == e.Realm {
255+
prev.Realm = ""
256+
}
257+
258+
// If this inner error hasn't Default Realm, then pull up the inner Realm
259+
if prev.Realm != DefaultRealm && e.Realm == DefaultRealm {
260+
e.Realm = prev.Realm
261+
prev.Realm = ""
262+
}
263+
244264
return e
245265
}
246266

pkg/errs/errs_test.go

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,26 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11-
func TestErrsNoArgs(t *testing.T) {
12-
assert.Panics(t, func() {
13-
_ = errs.E()
11+
func TestErrs(t *testing.T) {
12+
13+
t.Run("no arguments", func(t *testing.T) {
14+
assert.Panics(t, func() {
15+
_ = errs.E()
16+
})
17+
})
18+
19+
t.Run("unexpected argument", func(t *testing.T) {
20+
var any interface{}
21+
err := errs.E(any)
22+
assert.NotNil(t, err)
23+
24+
_, ok := err.(*errs.Error)
25+
assert.False(t, ok, "expected error should not be an errs.Error type, instead of a common error from fmt.Errorf")
26+
})
27+
28+
t.Run("check error kind alias", func(t *testing.T) {
29+
assert.Equal(t, "other_error", errs.Other.String())
30+
assert.Equal(t, "I/O_error", errs.IO.String())
1431
})
1532
}
1633

@@ -84,3 +101,26 @@ func TestMatch(t *testing.T) {
84101
match = errs.Match(want, err2)
85102
assert.False(t, match, "Expect to be mismatched, but matched")
86103
}
104+
105+
func TestUnauthenticatedE(t *testing.T) {
106+
107+
t.Run("default realm", func(t *testing.T) {
108+
err := errs.E(errs.Unauthenticated, errs.UserName("john@doe.com"))
109+
assert.NotNil(t, err)
110+
111+
e, ok := err.(*errs.Error)
112+
assert.True(t, ok)
113+
114+
assert.Equal(t, errs.DefaultRealm, e.Realm)
115+
})
116+
117+
t.Run("given realm", func(t *testing.T) {
118+
err := errs.E(errs.Unauthenticated, errs.Realm("admin"), errs.UserName("john@doe.com"))
119+
assert.NotNil(t, err)
120+
121+
e, ok := err.(*errs.Error)
122+
assert.True(t, ok)
123+
124+
assert.Equal(t, errs.Realm("admin"), e.Realm)
125+
})
126+
}

0 commit comments

Comments
 (0)