-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate_api_key_test.go
More file actions
71 lines (53 loc) · 1.83 KB
/
update_api_key_test.go
File metadata and controls
71 lines (53 loc) · 1.83 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0
package cmd_test
import (
"fmt"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/codesphere-cloud/oms/cli/cmd"
"github.com/codesphere-cloud/oms/internal/portal"
)
var _ = Describe("UpdateAPIKey", func() {
var (
mockPortal *portal.MockPortal
c cmd.UpdateAPIKeyCmd
)
BeforeEach(func() {
mockPortal = portal.NewMockPortal(GinkgoT())
c = cmd.UpdateAPIKeyCmd{}
})
Describe("Run", func() {
It("successfully updates the API key when given valid input", func() {
apiKeyID := "aaaaaaaaaaaaaaaaaaaaaa"
expiresAtStr := "2027-12-31T23:59:59Z"
expectedExpiresAt, err := time.Parse(time.RFC3339, expiresAtStr)
Expect(err).NotTo(HaveOccurred())
c.Opts.APIKeyID = apiKeyID
c.Opts.ExpiresAtStr = expiresAtStr
mockPortal.EXPECT().UpdateAPIKey(apiKeyID, expectedExpiresAt).Return(nil)
err = c.UpdateAPIKey(mockPortal)
Expect(err).NotTo(HaveOccurred())
})
It("returns an error for an invalid api key id format", func() {
apiKeyID := "not-a-valid-id"
expiresAtStr := "2027-12-31T23:59:59Z"
expectedExpiresAt, err := time.Parse(time.RFC3339, expiresAtStr)
Expect(err).NotTo(HaveOccurred())
c.Opts.APIKeyID = apiKeyID
c.Opts.ExpiresAtStr = expiresAtStr
mockPortal.EXPECT().UpdateAPIKey(apiKeyID, expectedExpiresAt).Return(fmt.Errorf("invalid api key id format"))
err = c.UpdateAPIKey(mockPortal)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("invalid api key id format"))
})
It("returns an error for an invalid date format", func() {
c.Opts.APIKeyID = "valid id"
c.Opts.ExpiresAtStr = "2025/123/123"
err := c.UpdateAPIKey(mockPortal)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("invalid date format"))
})
})
})