Skip to content

Commit ed26e97

Browse files
marainodopey
authored andcommitted
Fix tests.
1 parent c1bd156 commit ed26e97

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

api/errors_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"reflect"
66
"testing"
7+
8+
"github.com/smallstep/certificates/errs"
79
)
810

911
func TestError_MarshalJSON(t *testing.T) {
@@ -22,7 +24,7 @@ func TestError_MarshalJSON(t *testing.T) {
2224
}
2325
for _, tt := range tests {
2426
t.Run(tt.name, func(t *testing.T) {
25-
e := &Error{
27+
e := &errs.Error{
2628
Status: tt.fields.Status,
2729
Err: tt.fields.Err,
2830
}
@@ -45,15 +47,15 @@ func TestError_UnmarshalJSON(t *testing.T) {
4547
tests := []struct {
4648
name string
4749
args args
48-
expected *Error
50+
expected *errs.Error
4951
wantErr bool
5052
}{
51-
{"ok", args{[]byte(`{"status":400,"message":"bad request"}`)}, &Error{Status: 400, Err: fmt.Errorf("bad request")}, false},
52-
{"fail", args{[]byte(`{"status":"400","message":"bad request"}`)}, &Error{}, true},
53+
{"ok", args{[]byte(`{"status":400,"message":"bad request"}`)}, &errs.Error{Status: 400, Err: fmt.Errorf("bad request")}, false},
54+
{"fail", args{[]byte(`{"status":"400","message":"bad request"}`)}, &errs.Error{}, true},
5355
}
5456
for _, tt := range tests {
5557
t.Run(tt.name, func(t *testing.T) {
56-
e := new(Error)
58+
e := new(errs.Error)
5759
if err := e.UnmarshalJSON(tt.args.data); (err != nil) != tt.wantErr {
5860
t.Errorf("Error.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
5961
}

api/revoke_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,35 @@ import (
1616
"github.com/smallstep/assert"
1717
"github.com/smallstep/certificates/authority"
1818
"github.com/smallstep/certificates/authority/provisioner"
19+
"github.com/smallstep/certificates/errs"
1920
"github.com/smallstep/certificates/logging"
2021
)
2122

2223
func TestRevokeRequestValidate(t *testing.T) {
2324
type test struct {
2425
rr *RevokeRequest
25-
err *Error
26+
err *errs.Error
2627
}
2728
tests := map[string]test{
2829
"error/missing serial": {
2930
rr: &RevokeRequest{},
30-
err: &Error{Err: errors.New("missing serial"), Status: http.StatusBadRequest},
31+
err: &errs.Error{Err: errors.New("missing serial"), Status: http.StatusBadRequest},
3132
},
3233
"error/bad reasonCode": {
3334
rr: &RevokeRequest{
3435
Serial: "sn",
3536
ReasonCode: 15,
3637
Passive: true,
3738
},
38-
err: &Error{Err: errors.New("reasonCode out of bounds"), Status: http.StatusBadRequest},
39+
err: &errs.Error{Err: errors.New("reasonCode out of bounds"), Status: http.StatusBadRequest},
3940
},
4041
"error/non-passive not implemented": {
4142
rr: &RevokeRequest{
4243
Serial: "sn",
4344
ReasonCode: 8,
4445
Passive: false,
4546
},
46-
err: &Error{Err: errors.New("non-passive revocation not implemented"), Status: http.StatusNotImplemented},
47+
err: &errs.Error{Err: errors.New("non-passive revocation not implemented"), Status: http.StatusNotImplemented},
4748
},
4849
"ok": {
4950
rr: &RevokeRequest{
@@ -57,7 +58,7 @@ func TestRevokeRequestValidate(t *testing.T) {
5758
t.Run(name, func(t *testing.T) {
5859
if err := tc.rr.Validate(); err != nil {
5960
switch v := err.(type) {
60-
case *Error:
61+
case *errs.Error:
6162
assert.HasPrefix(t, v.Error(), tc.err.Error())
6263
assert.Equals(t, v.StatusCode(), tc.err.Status)
6364
default:
@@ -189,7 +190,7 @@ func Test_caHandler_Revoke(t *testing.T) {
189190
return nil, nil
190191
},
191192
revoke: func(ctx context.Context, opts *authority.RevokeOptions) error {
192-
return InternalServerError(errors.New("force"))
193+
return errs.InternalServerError(errors.New("force"))
193194
},
194195
},
195196
}

api/utils_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/pkg/errors"
12+
"github.com/smallstep/certificates/errs"
1213
"github.com/smallstep/certificates/logging"
1314
)
1415

@@ -108,7 +109,7 @@ func TestReadJSON(t *testing.T) {
108109
t.Errorf("ReadJSON() error = %v, wantErr %v", err, tt.wantErr)
109110
}
110111
if tt.wantErr {
111-
e, ok := err.(*Error)
112+
e, ok := err.(*errs.Error)
112113
if ok {
113114
if code := e.StatusCode(); code != 400 {
114115
t.Errorf("error.StatusCode() = %v, wants 400", code)

0 commit comments

Comments
 (0)