Skip to content

Commit 6b41317

Browse files
authored
add account test coverage (#636)
1 parent 00343d6 commit 6b41317

23 files changed

+1033
-0
lines changed

account_oauth_client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,14 @@ func (c *Client) DeleteOAuthClient(ctx context.Context, clientID string) error {
129129
err := doDELETERequest(ctx, c, e)
130130
return err
131131
}
132+
133+
// ResetOAuthClientSecret resets the OAuth Client secret for a client with a specified id
134+
func (c *Client) ResetOAuthClientSecret(ctx context.Context, clientID string) (*OAuthClient, error) {
135+
e := formatAPIPath("account/oauth-clients/%s/reset-secret", clientID)
136+
response, err := doPOSTRequest[OAuthClient, any](ctx, c, e)
137+
if err != nil {
138+
return nil, err
139+
}
140+
141+
return response, nil
142+
}

test/integration/account_oauth_client_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package integration
22

33
import (
44
"context"
5+
"github.com/stretchr/testify/assert"
56
"testing"
67

78
"github.com/linode/linodego"
@@ -68,6 +69,25 @@ func TestOAuthClients_List(t *testing.T) {
6869
}
6970
}
7071

72+
func TestOAuthClients_Reset(t *testing.T) {
73+
createOpts := linodego.OAuthClientCreateOptions{
74+
Public: true,
75+
RedirectURI: "https://example.com",
76+
Label: "go-client-test",
77+
}
78+
client, oauthClient, teardown, err := setupOAuthClient(t, createOpts, "fixtures/TestOAuthClients_Reset")
79+
defer teardown()
80+
if err != nil {
81+
t.Error(err)
82+
}
83+
oauthClientAfterReset, err := client.ResetOAuthClientSecret(context.Background(), oauthClient.ID)
84+
if err != nil {
85+
t.Errorf("Error resetting oauthClient secret, expected struct, got error %v", err)
86+
}
87+
88+
assert.NotEqual(t, oauthClient.Secret, oauthClientAfterReset.Secret, "Secret should have been reset")
89+
}
90+
7191
func setupOAuthClient(t *testing.T, createOpts linodego.OAuthClientCreateOptions, fixturesYaml string) (*linodego.Client, *linodego.OAuthClient, func(), error) {
7292
t.Helper()
7393
client, fixtureTeardown := createTestClient(t, fixturesYaml)
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
---
2+
version: 1
3+
interactions:
4+
- request:
5+
body: '{"redirect_uri":"https://example.com","label":"go-client-test","public":true}'
6+
form: {}
7+
headers:
8+
Accept:
9+
- application/json
10+
Content-Type:
11+
- application/json
12+
User-Agent:
13+
- linodego/dev https://github.com/linode/linodego
14+
url: https://api.linode.com/v4beta/account/oauth-clients
15+
method: POST
16+
response:
17+
body: '{"id": "757a5af92718d7369687", "redirect_uri": "https://example.com", "label":
18+
"go-client-test", "status": "active", "secret": "1950e1df7217e8f8f1543ba8b1d12c03e6088eb1429e10549e18c650b677015f",
19+
"thumbnail_url": null, "public": true}'
20+
headers:
21+
Access-Control-Allow-Credentials:
22+
- "true"
23+
Access-Control-Allow-Headers:
24+
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
25+
Access-Control-Allow-Methods:
26+
- HEAD, GET, OPTIONS, POST, PUT, DELETE
27+
Access-Control-Allow-Origin:
28+
- '*'
29+
Access-Control-Expose-Headers:
30+
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
31+
Akamai-Internal-Account:
32+
- '*'
33+
Cache-Control:
34+
- max-age=0, no-cache, no-store
35+
Connection:
36+
- keep-alive
37+
Content-Length:
38+
- "233"
39+
Content-Security-Policy:
40+
- default-src 'none'
41+
Content-Type:
42+
- application/json
43+
Expires:
44+
- Tue, 03 Dec 2024 01:14:47 GMT
45+
Pragma:
46+
- no-cache
47+
Strict-Transport-Security:
48+
- max-age=31536000
49+
Vary:
50+
- Authorization, X-Filter
51+
X-Accepted-Oauth-Scopes:
52+
- account:read_write
53+
X-Content-Type-Options:
54+
- nosniff
55+
X-Frame-Options:
56+
- DENY
57+
- DENY
58+
X-Oauth-Scopes:
59+
- '*'
60+
X-Ratelimit-Limit:
61+
- "1600"
62+
X-Xss-Protection:
63+
- 1; mode=block
64+
status: 200 OK
65+
code: 200
66+
duration: ""
67+
- request:
68+
body: ""
69+
form: {}
70+
headers:
71+
Accept:
72+
- application/json
73+
Content-Type:
74+
- application/json
75+
User-Agent:
76+
- linodego/dev https://github.com/linode/linodego
77+
url: https://api.linode.com/v4beta/account/oauth-clients/757a5af92718d7369687/reset-secret
78+
method: POST
79+
response:
80+
body: '{"id": "757a5af92718d7369687", "redirect_uri": "https://example.com", "label":
81+
"go-client-test", "status": "active", "secret": "af3ccc4a7d881a8a858593080d0bffb1e9c6b1917cb88e28bd2b10ad885679cb",
82+
"thumbnail_url": null, "public": true}'
83+
headers:
84+
Access-Control-Allow-Credentials:
85+
- "true"
86+
Access-Control-Allow-Headers:
87+
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
88+
Access-Control-Allow-Methods:
89+
- HEAD, GET, OPTIONS, POST, PUT, DELETE
90+
Access-Control-Allow-Origin:
91+
- '*'
92+
Access-Control-Expose-Headers:
93+
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
94+
Akamai-Internal-Account:
95+
- '*'
96+
Cache-Control:
97+
- max-age=0, no-cache, no-store
98+
Connection:
99+
- keep-alive
100+
Content-Length:
101+
- "233"
102+
Content-Security-Policy:
103+
- default-src 'none'
104+
Content-Type:
105+
- application/json
106+
Expires:
107+
- Tue, 03 Dec 2024 01:14:47 GMT
108+
Pragma:
109+
- no-cache
110+
Strict-Transport-Security:
111+
- max-age=31536000
112+
Vary:
113+
- Authorization, X-Filter
114+
X-Accepted-Oauth-Scopes:
115+
- account:read_write
116+
X-Content-Type-Options:
117+
- nosniff
118+
X-Frame-Options:
119+
- DENY
120+
- DENY
121+
X-Oauth-Scopes:
122+
- '*'
123+
X-Ratelimit-Limit:
124+
- "1600"
125+
X-Xss-Protection:
126+
- 1; mode=block
127+
status: 200 OK
128+
code: 200
129+
duration: ""
130+
- request:
131+
body: ""
132+
form: {}
133+
headers:
134+
Accept:
135+
- application/json
136+
Content-Type:
137+
- application/json
138+
User-Agent:
139+
- linodego/dev https://github.com/linode/linodego
140+
url: https://api.linode.com/v4beta/account/oauth-clients/757a5af92718d7369687
141+
method: DELETE
142+
response:
143+
body: '{}'
144+
headers:
145+
Access-Control-Allow-Credentials:
146+
- "true"
147+
Access-Control-Allow-Headers:
148+
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter
149+
Access-Control-Allow-Methods:
150+
- HEAD, GET, OPTIONS, POST, PUT, DELETE
151+
Access-Control-Allow-Origin:
152+
- '*'
153+
Access-Control-Expose-Headers:
154+
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status
155+
Akamai-Internal-Account:
156+
- '*'
157+
Cache-Control:
158+
- max-age=0, no-cache, no-store
159+
Connection:
160+
- keep-alive
161+
Content-Length:
162+
- "2"
163+
Content-Security-Policy:
164+
- default-src 'none'
165+
Content-Type:
166+
- application/json
167+
Expires:
168+
- Tue, 03 Dec 2024 01:14:48 GMT
169+
Pragma:
170+
- no-cache
171+
Strict-Transport-Security:
172+
- max-age=31536000
173+
Vary:
174+
- Authorization, X-Filter
175+
X-Accepted-Oauth-Scopes:
176+
- account:read_write
177+
X-Content-Type-Options:
178+
- nosniff
179+
X-Frame-Options:
180+
- DENY
181+
- DENY
182+
X-Oauth-Scopes:
183+
- '*'
184+
X-Ratelimit-Limit:
185+
- "1600"
186+
X-Xss-Protection:
187+
- 1; mode=block
188+
status: 200 OK
189+
code: 200
190+
duration: ""
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package unit
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/linode/linodego"
7+
"github.com/stretchr/testify/assert"
8+
"testing"
9+
)
10+
11+
func TestAccountAvailabilities_List(t *testing.T) {
12+
fixtureData, err := fixtures.GetFixture("account_availability_list")
13+
assert.NoError(t, err)
14+
15+
var base ClientBaseCase
16+
base.SetUp(t)
17+
defer base.TearDown(t)
18+
19+
base.MockGet("account/availability", fixtureData)
20+
21+
availabilities, err := base.Client.ListAccountAvailabilities(context.Background(), &linodego.ListOptions{})
22+
assert.NoError(t, err)
23+
24+
// Check specific region "us-central"
25+
var usCentralAvailability *linodego.AccountAvailability
26+
for _, availability := range availabilities {
27+
if availability.Region == "us-central" {
28+
usCentralAvailability = &availability
29+
break
30+
}
31+
}
32+
if usCentralAvailability == nil {
33+
t.Errorf("Expected region 'us-central' to be in the response, but it was not found")
34+
} else {
35+
expectedAvailable := []string{"Linodes", "NodeBalancers", "Block Storage", "Kubernetes"}
36+
if !equalSlices(usCentralAvailability.Available, expectedAvailable) {
37+
t.Errorf("Expected available resources for 'us-central' to be %v, but got %v", expectedAvailable, usCentralAvailability.Available)
38+
}
39+
40+
if len(usCentralAvailability.Unavailable) != 0 {
41+
t.Errorf("Expected no unavailable resources for 'us-central', but got %v", usCentralAvailability.Unavailable)
42+
}
43+
}
44+
45+
expectedRegionsCount := 40
46+
if len(availabilities) != expectedRegionsCount {
47+
t.Errorf("Expected %d regions, but got %d", expectedRegionsCount, len(availabilities))
48+
}
49+
}
50+
51+
func TestAccountAvailability_Get(t *testing.T) {
52+
fixtureData, err := fixtures.GetFixture("account_availability_get")
53+
assert.NoError(t, err)
54+
55+
var base ClientBaseCase
56+
base.SetUp(t)
57+
defer base.TearDown(t)
58+
59+
regionID := "us-east"
60+
61+
base.MockGet(fmt.Sprintf("account/availability/%s", regionID), fixtureData)
62+
63+
availability, err := base.Client.GetAccountAvailability(context.Background(), regionID)
64+
assert.NoError(t, err)
65+
66+
assert.Equal(t, "us-east", availability.Region, "Expected region to be 'us-east'")
67+
68+
expectedAvailable := []string{"Linodes", "NodeBalancers"}
69+
assert.ElementsMatch(t, expectedAvailable, availability.Available, "Available resources do not match the expected list")
70+
71+
expectedUnavailable := []string{"Kubernetes", "Block Storage"}
72+
assert.ElementsMatch(t, expectedUnavailable, availability.Unavailable, "Unavailable resources do not match the expected list")
73+
}
74+
75+
// Helper function to compare slices in assertion
76+
func equalSlices(a, b []string) bool {
77+
if len(a) != len(b) {
78+
return false
79+
}
80+
aMap := make(map[string]bool)
81+
for _, v := range a {
82+
aMap[v] = true
83+
}
84+
for _, v := range b {
85+
if !aMap[v] {
86+
return false
87+
}
88+
}
89+
return true
90+
}

0 commit comments

Comments
 (0)