Skip to content

Commit

Permalink
service_authorization: Remove default user id
Browse files Browse the repository at this point in the history
Only the serviceid needs to be default and normalized.
  • Loading branch information
noseglid committed Jun 20, 2022
1 parent 4a299a2 commit a386cf6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 62 deletions.
16 changes: 0 additions & 16 deletions fastly/fastly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ var testStatsClient = NewRealtimeStatsClient()
// testServiceID is the ID of the testing service.
var testServiceID = serviceIDForTest()

// testUserID is the ID of the testing user.
var testUserID = userIDForTest()

// Default ID of the testing service.
var defaultTestServiceID = "7i6HN3TK9wS159v2gPAZ8A"

// Default ID of the testing user.
var defaultTestUserID = "4tKBSuFhNEiIpNDxmmVydt"

const (
// ServiceTypeVCL is the type for VCL services.
ServiceTypeVCL = "vcl"
Expand All @@ -49,16 +43,6 @@ func serviceIDForTest() string {
return defaultTestServiceID
}

func userIDForTest() string {
uid := os.Getenv("FASTLY_TEST_USER_ID")

if uid != "" {
return uid
}

return defaultTestUserID
}

func vcrDisabled() bool {
vcrDisable := os.Getenv("VCR_DISABLE")

Expand Down
14 changes: 7 additions & 7 deletions fastly/fixtures/service_authorizations/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ interactions:
headers:
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
url: https://api.fastly.com/service-authorizations/3LA2qxhWzpRitVKTq9SsEU
method: DELETE
response:
body: '{"msg":"Record not found","detail":"Cannot find serviceauthorization ''dTYPkfosjJ6dMSBZNAPff''"}'
body: '{"msg":"Record not found","detail":"Cannot find serviceauthorization ''3LA2qxhWzpRitVKTq9SsEU''"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -19,11 +19,11 @@ interactions:
Content-Type:
- application/json
Date:
- Thu, 16 Jun 2022 14:54:33 GMT
- Mon, 20 Jun 2022 09:05:33 GMT
Fastly-Ratelimit-Remaining:
- "956"
- "966"
Fastly-Ratelimit-Reset:
- "1655391600"
- "1655719200"
Status:
- 404 Not Found
Strict-Transport-Security:
Expand All @@ -37,9 +37,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9035-CONTROL-SLWDC, cache-bma1646-BMA
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1641-BMA
X-Timer:
- S1655391273.306991,VS0,VE433
- S1655715933.446686,VS0,VE438
status: 404 Not Found
code: 404
duration: ""
14 changes: 7 additions & 7 deletions fastly/fixtures/service_authorizations/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 1
interactions:
- request:
body: |
{"data":{"type":"service_authorization","attributes":{"permission":"full"},"relationships":{"service":{"data":{"type":"service","id":"7i6HN3TK9wS159v2gPAZ8A"}},"user":{"data":{"type":"user","id":"4tKBSuFhNEiIpNDxmmVydt"}}}},"included":[{"type":"user","id":"4tKBSuFhNEiIpNDxmmVydt"},{"type":"service","id":"7i6HN3TK9wS159v2gPAZ8A"}]}
{"data":{"type":"service_authorization","attributes":{"permission":"full"},"relationships":{"service":{"data":{"type":"service","id":"7i6HN3TK9wS159v2gPAZ8A"}},"user":{"data":{"type":"user","id":"4tKBSuFhNEiIpNDxmmVydt"}}}},"included":[{"type":"service","id":"7i6HN3TK9wS159v2gPAZ8A"},{"type":"user","id":"4tKBSuFhNEiIpNDxmmVydt"}]}
form: {}
headers:
Accept:
Expand All @@ -15,7 +15,7 @@ interactions:
url: https://api.fastly.com/service-authorizations
method: POST
response:
body: '{"data":{"id":"dTYPkfosjJ6dMSBZNAPff","type":"service_authorization","attributes":{"created_at":"2022-06-16T14:54:32Z","updated_at":"2022-06-16T14:54:32Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
body: '{"data":{"id":"3LA2qxhWzpRitVKTq9SsEU","type":"service_authorization","attributes":{"created_at":"2022-06-20T09:05:32Z","updated_at":"2022-06-20T09:05:32Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -24,11 +24,11 @@ interactions:
Content-Type:
- application/vnd.api+json
Date:
- Thu, 16 Jun 2022 14:54:32 GMT
- Mon, 20 Jun 2022 09:05:32 GMT
Fastly-Ratelimit-Remaining:
- "959"
- "969"
Fastly-Ratelimit-Reset:
- "1655391600"
- "1655719200"
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -42,9 +42,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
- cache-control-slwdc9037-CONTROL-SLWDC, cache-bma1641-BMA
X-Timer:
- S1655391272.193824,VS0,VE172
- S1655715932.138355,VS0,VE362
status: 200 OK
code: 200
duration: ""
12 changes: 6 additions & 6 deletions fastly/fixtures/service_authorizations/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
headers:
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
url: https://api.fastly.com/service-authorizations/3LA2qxhWzpRitVKTq9SsEU
method: DELETE
response:
body: ""
Expand All @@ -17,11 +17,11 @@ interactions:
Cache-Control:
- no-store
Date:
- Thu, 16 Jun 2022 14:54:33 GMT
- Mon, 20 Jun 2022 09:05:33 GMT
Fastly-Ratelimit-Remaining:
- "957"
- "967"
Fastly-Ratelimit-Reset:
- "1655391600"
- "1655719200"
Status:
- 204 No Content
Strict-Transport-Security:
Expand All @@ -33,9 +33,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
- cache-control-slwdc9035-CONTROL-SLWDC, cache-bma1641-BMA
X-Timer:
- S1655391273.032612,VS0,VE260
- S1655715933.228193,VS0,VE203
status: 204 No Content
code: 204
duration: ""
10 changes: 5 additions & 5 deletions fastly/fixtures/service_authorizations/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ interactions:
headers:
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
url: https://api.fastly.com/service-authorizations/3LA2qxhWzpRitVKTq9SsEU
method: GET
response:
body: '{"data":{"id":"dTYPkfosjJ6dMSBZNAPff","type":"service_authorization","attributes":{"created_at":"2022-06-16T14:54:32Z","updated_at":"2022-06-16T14:54:32Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
body: '{"data":{"id":"3LA2qxhWzpRitVKTq9SsEU","type":"service_authorization","attributes":{"created_at":"2022-06-20T09:05:32Z","updated_at":"2022-06-20T09:05:32Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -19,7 +19,7 @@ interactions:
Content-Type:
- application/vnd.api+json
Date:
- Thu, 16 Jun 2022 14:54:32 GMT
- Mon, 20 Jun 2022 09:05:32 GMT
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -33,9 +33,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1641-BMA
X-Timer:
- S1655391272.387855,VS0,VE432
- S1655715933.614930,VS0,VE139
status: 200 OK
code: 200
duration: ""
16 changes: 8 additions & 8 deletions fastly/fixtures/service_authorizations/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 1
interactions:
- request:
body: |
{"data":{"type":"service_authorization","id":"dTYPkfosjJ6dMSBZNAPff","attributes":{"permission":"purge_select"}}}
{"data":{"type":"service_authorization","id":"3LA2qxhWzpRitVKTq9SsEU","attributes":{"permission":"purge_select"}}}
form: {}
headers:
Accept:
Expand All @@ -12,10 +12,10 @@ interactions:
- application/vnd.api+json
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
url: https://api.fastly.com/service-authorizations/3LA2qxhWzpRitVKTq9SsEU
method: PATCH
response:
body: '{"data":{"id":"dTYPkfosjJ6dMSBZNAPff","type":"service_authorization","attributes":{"created_at":"2022-06-16T14:54:32Z","updated_at":"2022-06-16T14:54:32Z","deleted_at":null,"permission":"purge_select"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
body: '{"data":{"id":"3LA2qxhWzpRitVKTq9SsEU","type":"service_authorization","attributes":{"created_at":"2022-06-20T09:05:32Z","updated_at":"2022-06-20T09:05:33Z","deleted_at":null,"permission":"purge_select"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -24,11 +24,11 @@ interactions:
Content-Type:
- application/vnd.api+json
Date:
- Thu, 16 Jun 2022 14:54:33 GMT
- Mon, 20 Jun 2022 09:05:33 GMT
Fastly-Ratelimit-Remaining:
- "958"
- "968"
Fastly-Ratelimit-Reset:
- "1655391600"
- "1655719200"
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -42,9 +42,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
- cache-control-slwdc9035-CONTROL-SLWDC, cache-bma1641-BMA
X-Timer:
- S1655391273.836430,VS0,VE181
- S1655715933.770167,VS0,VE391
status: 200 OK
code: 200
duration: ""
4 changes: 2 additions & 2 deletions fastly/service_authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestClient_ServiceAuthorizations(t *testing.T) {
record(t, fixtureBase+"create", func(c *Client) {
sa, err = c.CreateServiceAuthorization(&CreateServiceAuthorizationInput{
Service: &SAService{ID: testServiceID},
User: &SAUser{ID: testUserID},
User: &SAUser{ID: "4tKBSuFhNEiIpNDxmmVydt"},
Permission: "full",
})
})
Expand All @@ -37,7 +37,7 @@ func TestClient_ServiceAuthorizations(t *testing.T) {
t.Errorf("bad service id: %v", sa.Service.ID)
}

if sa.User.ID != testUserID {
if sa.User.ID != "4tKBSuFhNEiIpNDxmmVydt" {
t.Errorf("bad user id: %v", sa.User.ID)
}

Expand Down
11 changes: 0 additions & 11 deletions scripts/fixFixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@ set -e

FASTLY_TEST_SERVICE_ID=$1
DEFAULT_TEST_SERVICE_ID="7i6HN3TK9wS159v2gPAZ8A"
DEFAULT_TEST_USER_ID="4tKBSuFhNEiIpNDxmmVydt"
FIXTURESDIR="$(pwd)/fastly/fixtures/"

if [[ -z ${FASTLY_TEST_SERVICE_ID} && -z $1 ]]; then
echo "You must supply a service ID as the first argument"
exit
fi

if [[ -z ${FASTLY_TEST_USER_ID} && -z $2 ]]; then
echo "You must supply a user ID as the second argument"
exit
fi

for file in $(grep --recursive --files-with-matches "${FASTLY_TEST_SERVICE_ID}" "${FIXTURESDIR}")
do
sed -i.bak "s/${FASTLY_TEST_SERVICE_ID}/${DEFAULT_TEST_SERVICE_ID}/g" "$file" && rm "${file}.bak"
done

for file in $(grep --recursive --files-with-matches "${FASTLY_TEST_USER_ID}" "${FIXTURESDIR}")
do
sed -i.bak "s/${FASTLY_TEST_USER_ID}/${DEFAULT_TEST_USER_ID}/g" "$file" && rm "${file}.bak"
done

0 comments on commit a386cf6

Please sign in to comment.