forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add account test coverage (linode#636)
- Loading branch information
1 parent
00343d6
commit 6b41317
Showing
23 changed files
with
1,033 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: '{"redirect_uri":"https://example.com","label":"go-client-test","public":true}' | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- linodego/dev https://github.com/linode/linodego | ||
url: https://api.linode.com/v4beta/account/oauth-clients | ||
method: POST | ||
response: | ||
body: '{"id": "757a5af92718d7369687", "redirect_uri": "https://example.com", "label": | ||
"go-client-test", "status": "active", "secret": "1950e1df7217e8f8f1543ba8b1d12c03e6088eb1429e10549e18c650b677015f", | ||
"thumbnail_url": null, "public": true}' | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- "true" | ||
Access-Control-Allow-Headers: | ||
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter | ||
Access-Control-Allow-Methods: | ||
- HEAD, GET, OPTIONS, POST, PUT, DELETE | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Access-Control-Expose-Headers: | ||
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status | ||
Akamai-Internal-Account: | ||
- '*' | ||
Cache-Control: | ||
- max-age=0, no-cache, no-store | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "233" | ||
Content-Security-Policy: | ||
- default-src 'none' | ||
Content-Type: | ||
- application/json | ||
Expires: | ||
- Tue, 03 Dec 2024 01:14:47 GMT | ||
Pragma: | ||
- no-cache | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Authorization, X-Filter | ||
X-Accepted-Oauth-Scopes: | ||
- account:read_write | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
- DENY | ||
X-Oauth-Scopes: | ||
- '*' | ||
X-Ratelimit-Limit: | ||
- "1600" | ||
X-Xss-Protection: | ||
- 1; mode=block | ||
status: 200 OK | ||
code: 200 | ||
duration: "" | ||
- request: | ||
body: "" | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- linodego/dev https://github.com/linode/linodego | ||
url: https://api.linode.com/v4beta/account/oauth-clients/757a5af92718d7369687/reset-secret | ||
method: POST | ||
response: | ||
body: '{"id": "757a5af92718d7369687", "redirect_uri": "https://example.com", "label": | ||
"go-client-test", "status": "active", "secret": "af3ccc4a7d881a8a858593080d0bffb1e9c6b1917cb88e28bd2b10ad885679cb", | ||
"thumbnail_url": null, "public": true}' | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- "true" | ||
Access-Control-Allow-Headers: | ||
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter | ||
Access-Control-Allow-Methods: | ||
- HEAD, GET, OPTIONS, POST, PUT, DELETE | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Access-Control-Expose-Headers: | ||
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status | ||
Akamai-Internal-Account: | ||
- '*' | ||
Cache-Control: | ||
- max-age=0, no-cache, no-store | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "233" | ||
Content-Security-Policy: | ||
- default-src 'none' | ||
Content-Type: | ||
- application/json | ||
Expires: | ||
- Tue, 03 Dec 2024 01:14:47 GMT | ||
Pragma: | ||
- no-cache | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Authorization, X-Filter | ||
X-Accepted-Oauth-Scopes: | ||
- account:read_write | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
- DENY | ||
X-Oauth-Scopes: | ||
- '*' | ||
X-Ratelimit-Limit: | ||
- "1600" | ||
X-Xss-Protection: | ||
- 1; mode=block | ||
status: 200 OK | ||
code: 200 | ||
duration: "" | ||
- request: | ||
body: "" | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- linodego/dev https://github.com/linode/linodego | ||
url: https://api.linode.com/v4beta/account/oauth-clients/757a5af92718d7369687 | ||
method: DELETE | ||
response: | ||
body: '{}' | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- "true" | ||
Access-Control-Allow-Headers: | ||
- Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter | ||
Access-Control-Allow-Methods: | ||
- HEAD, GET, OPTIONS, POST, PUT, DELETE | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Access-Control-Expose-Headers: | ||
- X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status | ||
Akamai-Internal-Account: | ||
- '*' | ||
Cache-Control: | ||
- max-age=0, no-cache, no-store | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- "2" | ||
Content-Security-Policy: | ||
- default-src 'none' | ||
Content-Type: | ||
- application/json | ||
Expires: | ||
- Tue, 03 Dec 2024 01:14:48 GMT | ||
Pragma: | ||
- no-cache | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Authorization, X-Filter | ||
X-Accepted-Oauth-Scopes: | ||
- account:read_write | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- DENY | ||
- DENY | ||
X-Oauth-Scopes: | ||
- '*' | ||
X-Ratelimit-Limit: | ||
- "1600" | ||
X-Xss-Protection: | ||
- 1; mode=block | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package unit | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/linode/linodego" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestAccountAvailabilities_List(t *testing.T) { | ||
fixtureData, err := fixtures.GetFixture("account_availability_list") | ||
assert.NoError(t, err) | ||
|
||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
base.MockGet("account/availability", fixtureData) | ||
|
||
availabilities, err := base.Client.ListAccountAvailabilities(context.Background(), &linodego.ListOptions{}) | ||
assert.NoError(t, err) | ||
|
||
// Check specific region "us-central" | ||
var usCentralAvailability *linodego.AccountAvailability | ||
for _, availability := range availabilities { | ||
if availability.Region == "us-central" { | ||
usCentralAvailability = &availability | ||
break | ||
} | ||
} | ||
if usCentralAvailability == nil { | ||
t.Errorf("Expected region 'us-central' to be in the response, but it was not found") | ||
} else { | ||
expectedAvailable := []string{"Linodes", "NodeBalancers", "Block Storage", "Kubernetes"} | ||
if !equalSlices(usCentralAvailability.Available, expectedAvailable) { | ||
t.Errorf("Expected available resources for 'us-central' to be %v, but got %v", expectedAvailable, usCentralAvailability.Available) | ||
} | ||
|
||
if len(usCentralAvailability.Unavailable) != 0 { | ||
t.Errorf("Expected no unavailable resources for 'us-central', but got %v", usCentralAvailability.Unavailable) | ||
} | ||
} | ||
|
||
expectedRegionsCount := 40 | ||
if len(availabilities) != expectedRegionsCount { | ||
t.Errorf("Expected %d regions, but got %d", expectedRegionsCount, len(availabilities)) | ||
} | ||
} | ||
|
||
func TestAccountAvailability_Get(t *testing.T) { | ||
fixtureData, err := fixtures.GetFixture("account_availability_get") | ||
assert.NoError(t, err) | ||
|
||
var base ClientBaseCase | ||
base.SetUp(t) | ||
defer base.TearDown(t) | ||
|
||
regionID := "us-east" | ||
|
||
base.MockGet(fmt.Sprintf("account/availability/%s", regionID), fixtureData) | ||
|
||
availability, err := base.Client.GetAccountAvailability(context.Background(), regionID) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, "us-east", availability.Region, "Expected region to be 'us-east'") | ||
|
||
expectedAvailable := []string{"Linodes", "NodeBalancers"} | ||
assert.ElementsMatch(t, expectedAvailable, availability.Available, "Available resources do not match the expected list") | ||
|
||
expectedUnavailable := []string{"Kubernetes", "Block Storage"} | ||
assert.ElementsMatch(t, expectedUnavailable, availability.Unavailable, "Unavailable resources do not match the expected list") | ||
} | ||
|
||
// Helper function to compare slices in assertion | ||
func equalSlices(a, b []string) bool { | ||
if len(a) != len(b) { | ||
return false | ||
} | ||
aMap := make(map[string]bool) | ||
for _, v := range a { | ||
aMap[v] = true | ||
} | ||
for _, v := range b { | ||
if !aMap[v] { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
Oops, something went wrong.