Skip to content

Commit 5f224b7

Browse files
committed
Add tests for Provisioner Admin API
1 parent 43a78f4 commit 5f224b7

File tree

4 files changed

+1122
-15
lines changed

4 files changed

+1122
-15
lines changed

api/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ type MockAuthority struct {
487487
rekey func(oldCert *x509.Certificate, pk crypto.PublicKey) ([]*x509.Certificate, error)
488488
loadProvisionerByCertificate func(cert *x509.Certificate) (provisioner.Interface, error)
489489
MockLoadProvisionerByName func(name string) (provisioner.Interface, error)
490-
getProvisioners func(nextCursor string, limit int) (provisioner.List, string, error)
490+
MockGetProvisioners func(nextCursor string, limit int) (provisioner.List, string, error)
491491
revoke func(context.Context, *authority.RevokeOptions) error
492492
getEncryptedKey func(kid string) (string, error)
493493
getRoots func() ([]*x509.Certificate, error)
@@ -567,8 +567,8 @@ func (m *MockAuthority) Rekey(oldcert *x509.Certificate, pk crypto.PublicKey) ([
567567
}
568568

569569
func (m *MockAuthority) GetProvisioners(nextCursor string, limit int) (provisioner.List, string, error) {
570-
if m.getProvisioners != nil {
571-
return m.getProvisioners(nextCursor, limit)
570+
if m.MockGetProvisioners != nil {
571+
return m.MockGetProvisioners(nextCursor, limit)
572572
}
573573
return m.ret1.(provisioner.List), m.ret2.(string), m.err
574574
}

authority/admin/api/acme_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,21 +1154,23 @@ func TestHandler_GetExternalAccountKeys(t *testing.T) {
11541154
assert.Equals(t, tc.err.StatusCode(), res.StatusCode)
11551155
assert.Equals(t, tc.err.Detail, adminErr.Detail)
11561156
assert.Equals(t, []string{"application/json"}, res.Header["Content-Type"])
1157-
} else {
1158-
body, err := io.ReadAll(res.Body)
1159-
res.Body.Close()
1160-
assert.FatalError(t, err)
1157+
return
1158+
}
11611159

1162-
response := GetExternalAccountKeysResponse{}
1163-
assert.FatalError(t, json.Unmarshal(bytes.TrimSpace(body), &response))
1160+
body, err := io.ReadAll(res.Body)
1161+
res.Body.Close()
1162+
assert.FatalError(t, err)
11641163

1165-
assert.Equals(t, []string{"application/json"}, res.Header["Content-Type"])
1164+
response := GetExternalAccountKeysResponse{}
1165+
assert.FatalError(t, json.Unmarshal(bytes.TrimSpace(body), &response))
11661166

1167-
opts := []cmp.Option{cmpopts.IgnoreUnexported(linkedca.EABKey{}, timestamppb.Timestamp{})}
1168-
if !cmp.Equal(tc.resp, response, opts...) {
1169-
t.Errorf("h.GetExternalAccountKeys diff =\n%s", cmp.Diff(tc.resp, response, opts...))
1170-
}
1167+
assert.Equals(t, []string{"application/json"}, res.Header["Content-Type"])
1168+
1169+
opts := []cmp.Option{cmpopts.IgnoreUnexported(linkedca.EABKey{}, timestamppb.Timestamp{})}
1170+
if !cmp.Equal(tc.resp, response, opts...) {
1171+
t.Errorf("h.GetExternalAccountKeys diff =\n%s", cmp.Diff(tc.resp, response, opts...))
11711172
}
1173+
11721174
})
11731175
}
11741176
}

authority/admin/api/provisioner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (h *Handler) GetProvisioners(w http.ResponseWriter, r *http.Request) {
5454
cursor, limit, err := api.ParseCursor(r)
5555
if err != nil {
5656
api.WriteError(w, admin.WrapError(admin.ErrorBadRequestType, err,
57-
"error parsing cursor & limit query params"))
57+
"error parsing cursor and limit from query params"))
5858
return
5959
}
6060

0 commit comments

Comments
 (0)