Skip to content

Commit

Permalink
Merge pull request cloudflare#659 from jacobbednarz/namespace-test-ac…
Browse files Browse the repository at this point in the history
…count-and-zone-ids

tests: namespace `zoneID` and `accountID` placeholders
  • Loading branch information
jacobbednarz authored Jul 1, 2021
2 parents 590aa29 + 3ff7cbf commit 94cefa0
Show file tree
Hide file tree
Showing 21 changed files with 240 additions and 275 deletions.
60 changes: 30 additions & 30 deletions access_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ func TestAccessApplications(t *testing.T) {
CustomDenyURL: "https://www.cloudflare.com",
}}

mux.HandleFunc("/accounts/"+accountID+"/access/apps", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps", handler)

actual, _, err := client.AccessApplications(context.Background(), accountID, PaginationOptions{})
actual, _, err := client.AccessApplications(context.Background(), testAccountID, PaginationOptions{})

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/apps", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/apps", handler)

actual, _, err = client.ZoneLevelAccessApplications(context.Background(), zoneID, PaginationOptions{})
actual, _, err = client.ZoneLevelAccessApplications(context.Background(), testZoneID, PaginationOptions{})

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
Expand Down Expand Up @@ -133,17 +133,17 @@ func TestAccessApplication(t *testing.T) {
CustomDenyURL: "https://www.cloudflare.com",
}

mux.HandleFunc("/accounts/"+accountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)

actual, err := client.AccessApplication(context.Background(), accountID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")
actual, err := client.AccessApplication(context.Background(), testAccountID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)

actual, err = client.ZoneLevelAccessApplication(context.Background(), zoneID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")
actual, err = client.ZoneLevelAccessApplication(context.Background(), testZoneID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
Expand Down Expand Up @@ -198,9 +198,9 @@ func TestCreateAccessApplications(t *testing.T) {
UpdatedAt: &updatedAt,
}

mux.HandleFunc("/accounts/"+accountID+"/access/apps", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps", handler)

actual, err := client.CreateAccessApplication(context.Background(), accountID, AccessApplication{
actual, err := client.CreateAccessApplication(context.Background(), testAccountID, AccessApplication{
Name: "Admin Site",
Domain: "test.example.com/admin",
SessionDuration: "24h",
Expand All @@ -210,9 +210,9 @@ func TestCreateAccessApplications(t *testing.T) {
assert.Equal(t, fullAccessApplication, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/apps", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/apps", handler)

actual, err = client.CreateZoneLevelAccessApplication(context.Background(), zoneID, AccessApplication{
actual, err = client.CreateZoneLevelAccessApplication(context.Background(), testZoneID, AccessApplication{
Name: "Admin Site",
Domain: "test.example.com/admin",
SessionDuration: "24h",
Expand Down Expand Up @@ -271,17 +271,17 @@ func TestUpdateAccessApplication(t *testing.T) {
UpdatedAt: &updatedAt,
}

mux.HandleFunc("/accounts/"+accountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)

actual, err := client.UpdateAccessApplication(context.Background(), accountID, fullAccessApplication)
actual, err := client.UpdateAccessApplication(context.Background(), testAccountID, fullAccessApplication)

if assert.NoError(t, err) {
assert.Equal(t, fullAccessApplication, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)

actual, err = client.UpdateZoneLevelAccessApplication(context.Background(), zoneID, fullAccessApplication)
actual, err = client.UpdateZoneLevelAccessApplication(context.Background(), testZoneID, fullAccessApplication)

if assert.NoError(t, err) {
assert.Equal(t, fullAccessApplication, actual)
Expand All @@ -292,10 +292,10 @@ func TestUpdateAccessApplicationWithMissingID(t *testing.T) {
setup()
defer teardown()

_, err := client.UpdateAccessApplication(context.Background(), zoneID, AccessApplication{})
_, err := client.UpdateAccessApplication(context.Background(), testZoneID, AccessApplication{})
assert.EqualError(t, err, "access application ID cannot be empty")

_, err = client.UpdateZoneLevelAccessApplication(context.Background(), zoneID, AccessApplication{})
_, err = client.UpdateZoneLevelAccessApplication(context.Background(), testZoneID, AccessApplication{})
assert.EqualError(t, err, "access application ID cannot be empty")
}

Expand All @@ -317,13 +317,13 @@ func TestDeleteAccessApplication(t *testing.T) {
`)
}

mux.HandleFunc("/accounts/"+accountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
err := client.DeleteAccessApplication(context.Background(), accountID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
err := client.DeleteAccessApplication(context.Background(), testAccountID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")

assert.NoError(t, err)

mux.HandleFunc("/zones/"+zoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
err = client.DeleteZoneLevelAccessApplication(context.Background(), zoneID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")
mux.HandleFunc("/zones/"+testZoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
err = client.DeleteZoneLevelAccessApplication(context.Background(), testZoneID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")

assert.NoError(t, err)
}
Expand All @@ -343,13 +343,13 @@ func TestRevokeAccessApplicationTokens(t *testing.T) {
`)
}

mux.HandleFunc("/accounts/"+accountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db/revoke-tokens", handler)
err := client.RevokeAccessApplicationTokens(context.Background(), accountID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db/revoke-tokens", handler)
err := client.RevokeAccessApplicationTokens(context.Background(), testAccountID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")

assert.NoError(t, err)

mux.HandleFunc("/zones/"+zoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db/revoke-tokens", handler)
err = client.RevokeZoneLevelAccessApplicationTokens(context.Background(), zoneID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")
mux.HandleFunc("/zones/"+testZoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db/revoke-tokens", handler)
err = client.RevokeZoneLevelAccessApplicationTokens(context.Background(), testZoneID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")

assert.NoError(t, err)
}
Expand Down Expand Up @@ -411,17 +411,17 @@ func TestAccessApplicationWithCORS(t *testing.T) {
},
}

mux.HandleFunc("/accounts/"+accountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)

actual, err := client.AccessApplication(context.Background(), accountID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")
actual, err := client.AccessApplication(context.Background(), testAccountID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/apps/480f4f69-1a28-4fdd-9240-1ed29f0ac1db", handler)

actual, err = client.ZoneLevelAccessApplication(context.Background(), zoneID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")
actual, err = client.ZoneLevelAccessApplication(context.Background(), testZoneID, "480f4f69-1a28-4fdd-9240-1ed29f0ac1db")

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
Expand Down
32 changes: 16 additions & 16 deletions access_ca_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ func TestAcessCACertificate(t *testing.T) {
PublicKey: "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTI...3urg/XpGMdgaSs5ZdptUPw= [email protected]",
}

mux.HandleFunc("/accounts/"+accountID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)

actual, err := client.AccessCACertificate(context.Background(), accountID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")
actual, err := client.AccessCACertificate(context.Background(), testAccountID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)

actual, err = client.ZoneLevelAccessCACertificate(context.Background(), zoneID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")
actual, err = client.ZoneLevelAccessCACertificate(context.Background(), testZoneID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
Expand Down Expand Up @@ -78,17 +78,17 @@ func TestAcessCACertificates(t *testing.T) {
PublicKey: "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTI...3urg/XpGMdgaSs5ZdptUPw= [email protected]",
}}

mux.HandleFunc("/accounts/"+accountID+"/access/apps/ca", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps/ca", handler)

actual, err := client.AccessCACertificates(context.Background(), accountID)
actual, err := client.AccessCACertificates(context.Background(), testAccountID)

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/apps/ca", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/apps/ca", handler)

actual, err = client.ZoneLevelAccessCACertificates(context.Background(), zoneID)
actual, err = client.ZoneLevelAccessCACertificates(context.Background(), testZoneID)

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
Expand Down Expand Up @@ -121,17 +121,17 @@ func TestCreateAcessCACertificates(t *testing.T) {
PublicKey: "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTI...3urg/XpGMdgaSs5ZdptUPw= [email protected]",
}

mux.HandleFunc("/accounts/"+accountID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)

actual, err := client.CreateAccessCACertificate(context.Background(), accountID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")
actual, err := client.CreateAccessCACertificate(context.Background(), testAccountID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)

actual, err = client.CreateZoneLevelAccessCACertificate(context.Background(), zoneID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")
actual, err = client.CreateZoneLevelAccessCACertificate(context.Background(), testZoneID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
Expand All @@ -156,15 +156,15 @@ func TestDeleteAcessCACertificates(t *testing.T) {
`)
}

mux.HandleFunc("/accounts/"+accountID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)

err := client.DeleteAccessCACertificate(context.Background(), accountID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")
err := client.DeleteAccessCACertificate(context.Background(), testAccountID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")

assert.NoError(t, err)

mux.HandleFunc("/zones/"+zoneID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/apps/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/ca", handler)

err = client.DeleteZoneLevelAccessCACertificate(context.Background(), zoneID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")
err = client.DeleteZoneLevelAccessCACertificate(context.Background(), testZoneID, "f174e90a-fafe-4643-bbbc-4a0ed4fc8415")

assert.NoError(t, err)
}
44 changes: 22 additions & 22 deletions access_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ func TestAccessGroups(t *testing.T) {
`)
}

mux.HandleFunc("/accounts/"+accountID+"/access/groups", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/groups", handler)

actual, _, err := client.AccessGroups(context.Background(), accountID, pageOptions)
actual, _, err := client.AccessGroups(context.Background(), testAccountID, pageOptions)

if assert.NoError(t, err) {
assert.Equal(t, []AccessGroup{expectedAccessGroup}, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/groups", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/groups", handler)

actual, _, err = client.ZoneLevelAccessGroups(context.Background(), zoneID, pageOptions)
actual, _, err = client.ZoneLevelAccessGroups(context.Background(), testZoneID, pageOptions)

if assert.NoError(t, err) {
assert.Equal(t, []AccessGroup{expectedAccessGroup}, actual)
Expand Down Expand Up @@ -138,17 +138,17 @@ func TestAccessGroup(t *testing.T) {
`)
}

mux.HandleFunc("/accounts/"+accountID+"/access/groups/"+accessGroupID, handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/groups/"+accessGroupID, handler)

actual, err := client.AccessGroup(context.Background(), accountID, accessGroupID)
actual, err := client.AccessGroup(context.Background(), testAccountID, accessGroupID)

if assert.NoError(t, err) {
assert.Equal(t, expectedAccessGroup, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/groups/"+accessGroupID, handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/groups/"+accessGroupID, handler)

actual, err = client.ZoneLevelAccessGroup(context.Background(), zoneID, accessGroupID)
actual, err = client.ZoneLevelAccessGroup(context.Background(), testZoneID, accessGroupID)

if assert.NoError(t, err) {
assert.Equal(t, expectedAccessGroup, actual)
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestCreateAccessGroup(t *testing.T) {
`)
}

mux.HandleFunc("/accounts/"+accountID+"/access/groups", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/access/groups", handler)

accessGroup := AccessGroup{
Name: "Allow devs",
Expand All @@ -218,15 +218,15 @@ func TestCreateAccessGroup(t *testing.T) {
},
}

actual, err := client.CreateAccessGroup(context.Background(), accountID, accessGroup)
actual, err := client.CreateAccessGroup(context.Background(), testAccountID, accessGroup)

if assert.NoError(t, err) {
assert.Equal(t, expectedAccessGroup, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/groups", handler)
mux.HandleFunc("/zones/"+testZoneID+"/access/groups", handler)

actual, err = client.CreateZoneLevelAccessGroup(context.Background(), zoneID, accessGroup)
actual, err = client.CreateZoneLevelAccessGroup(context.Background(), testZoneID, accessGroup)

if assert.NoError(t, err) {
assert.Equal(t, expectedAccessGroup, actual)
Expand Down Expand Up @@ -275,15 +275,15 @@ func TestUpdateAccessGroup(t *testing.T) {
`)
}

mux.HandleFunc("/accounts/"+accountID+"/access/groups/"+accessGroupID, handler)
actual, err := client.UpdateAccessGroup(context.Background(), accountID, expectedAccessGroup)
mux.HandleFunc("/accounts/"+testAccountID+"/access/groups/"+accessGroupID, handler)
actual, err := client.UpdateAccessGroup(context.Background(), testAccountID, expectedAccessGroup)

if assert.NoError(t, err) {
assert.Equal(t, expectedAccessGroup, actual)
}

mux.HandleFunc("/zones/"+zoneID+"/access/groups/"+accessGroupID, handler)
actual, err = client.UpdateZoneLevelAccessGroup(context.Background(), zoneID, expectedAccessGroup)
mux.HandleFunc("/zones/"+testZoneID+"/access/groups/"+accessGroupID, handler)
actual, err = client.UpdateZoneLevelAccessGroup(context.Background(), testZoneID, expectedAccessGroup)

if assert.NoError(t, err) {
assert.Equal(t, expectedAccessGroup, actual)
Expand All @@ -294,10 +294,10 @@ func TestUpdateAccessGroupWithMissingID(t *testing.T) {
setup()
defer teardown()

_, err := client.UpdateAccessGroup(context.Background(), accountID, AccessGroup{})
_, err := client.UpdateAccessGroup(context.Background(), testAccountID, AccessGroup{})
assert.EqualError(t, err, "access group ID cannot be empty")

_, err = client.UpdateZoneLevelAccessGroup(context.Background(), zoneID, AccessGroup{})
_, err = client.UpdateZoneLevelAccessGroup(context.Background(), testZoneID, AccessGroup{})
assert.EqualError(t, err, "access group ID cannot be empty")
}

Expand All @@ -319,13 +319,13 @@ func TestDeleteAccessGroup(t *testing.T) {
`)
}

mux.HandleFunc("/accounts/"+accountID+"/access/groups/"+accessGroupID, handler)
err := client.DeleteAccessGroup(context.Background(), accountID, accessGroupID)
mux.HandleFunc("/accounts/"+testAccountID+"/access/groups/"+accessGroupID, handler)
err := client.DeleteAccessGroup(context.Background(), testAccountID, accessGroupID)

assert.NoError(t, err)

mux.HandleFunc("/zones/"+zoneID+"/access/groups/"+accessGroupID, handler)
err = client.DeleteZoneLevelAccessGroup(context.Background(), zoneID, accessGroupID)
mux.HandleFunc("/zones/"+testZoneID+"/access/groups/"+accessGroupID, handler)
err = client.DeleteZoneLevelAccessGroup(context.Background(), testZoneID, accessGroupID)

assert.NoError(t, err)
}
Loading

0 comments on commit 94cefa0

Please sign in to comment.