Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(mux): handle url encoding in definitions #3653

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions observatory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestObservatoryPageTrend(t *testing.T) {
}
`)
}
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/trend", handler)
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/trend", handler)
want := ObservatoryPageTrend{
PerformanceScore: []*int{nil, IntPtr(100)},
TTFB: []*int{nil, IntPtr(10)},
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestListObservatoryPageTests(t *testing.T) {
}
`, pageTestJSON)
}
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/tests", handler)
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/tests", handler)
want := []ObservatoryPageTest{
pageTest,
}
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestCreateObservatoryPageTest(t *testing.T) {
}
`, pageTestJSON)
}
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/tests", handler)
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/tests", handler)
want := pageTest
test, err := client.CreateObservatoryPageTest(context.Background(), ZoneIdentifier(testZoneID), CreateObservatoryPageTestParams{
URL: testURL,
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestDeleteObservatoryPageTests(t *testing.T) {
}
`)
}
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/tests", handler)
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/tests", handler)
want := 2
count, err := client.DeleteObservatoryPageTests(context.Background(), ZoneIdentifier(testZoneID), DeleteObservatoryPageTestsParams{
URL: testURL,
Expand Down Expand Up @@ -364,7 +364,7 @@ func TestGetObservatoryPageTest(t *testing.T) {
}
`, pageTestJSON)
}
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+testURL+"/tests/"+observatoryTestID, handler)
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/pages/"+escapedTestURL+"/tests/"+observatoryTestID, handler)
want := pageTest
test, err := client.GetObservatoryPageTest(context.Background(), ZoneIdentifier(testZoneID), GetObservatoryPageTestParams{
TestID: observatoryTestID,
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestCreateObservatoryScheduledPageTest(t *testing.T) {
}
`, scheduledPageTestJSON)
}
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+testURL, handler)
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+escapedTestURL, handler)
want := scheduledPageTest
pages, err := client.CreateObservatoryScheduledPageTest(context.Background(), ZoneIdentifier(testZoneID), CreateObservatoryScheduledPageTestParams{
Frequency: frequency,
Expand Down Expand Up @@ -422,7 +422,7 @@ func TestObservatoryScheduledPageTest(t *testing.T) {
}
`, scheduleJSON)
}
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+testURL, handler)
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+escapedTestURL, handler)
want := schedule
schedule, err := client.GetObservatoryScheduledPageTest(context.Background(), ZoneIdentifier(testZoneID), GetObservatoryScheduledPageTestParams{
URL: testURL,
Expand All @@ -446,13 +446,13 @@ func TestDeleteObservatoryScheduledPageTest(t *testing.T) {
"success": true,
"errors": [],
"messages": [],
"result": {
"result": {
"count": 2
}
}
`)
}
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+testURL, handler)
mux.HandleFunc("/zones/"+testZoneID+"/speed_api/schedule/"+escapedTestURL, handler)
want := 2
count, err := client.DeleteObservatoryScheduledPageTest(context.Background(), ZoneIdentifier(testZoneID), DeleteObservatoryScheduledPageTestParams{
URL: testURL,
Expand Down
7 changes: 4 additions & 3 deletions pages_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"time"

"github.com/goccy/go-json"
Expand Down Expand Up @@ -254,7 +255,7 @@ func (api *API) GetPagesProject(ctx context.Context, rc *ResourceContainer, proj
return PagesProject{}, ErrMissingAccountID
}

uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, projectName)
uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, url.PathEscape(projectName))
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return PagesProject{}, err
Expand Down Expand Up @@ -299,7 +300,7 @@ func (api *API) UpdatePagesProject(ctx context.Context, rc *ResourceContainer, p
return PagesProject{}, ErrMissingIdentifier
}

uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, params.ID)
uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, url.PathEscape(params.ID))
res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params)
if err != nil {
return PagesProject{}, err
Expand All @@ -319,7 +320,7 @@ func (api *API) DeletePagesProject(ctx context.Context, rc *ResourceContainer, p
if rc.Identifier == "" {
return ErrMissingAccountID
}
uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, projectName)
uri := fmt.Sprintf("/accounts/%s/pages/projects/%s", rc.Identifier, url.PathEscape(projectName))
res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions pages_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func TestPagesProject(t *testing.T) {
}`, testPagesProjectResponse)
}

mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test Pages Project", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test%20Pages%20Project", handler)

_, err := client.GetPagesProject(context.Background(), AccountIdentifier(""), "Test Pages Project")
if assert.Error(t, err) {
Expand Down Expand Up @@ -631,7 +631,7 @@ func TestUpdatePagesProject(t *testing.T) {
}`, testPagesProjectResponse)
}

mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test Pages Project", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test%20Pages%20Project", handler)

_, err := client.UpdatePagesProject(context.Background(), AccountIdentifier(""), *updateAttributes)
if assert.Error(t, err) {
Expand Down Expand Up @@ -659,7 +659,7 @@ func TestDeletePagesProject(t *testing.T) {
}`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test Pages Project", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/pages/projects/Test%20Pages%20Project", handler)

err := client.DeletePagesProject(context.Background(), AccountIdentifier(""), "Test Pages Project")
if assert.Error(t, err) {
Expand Down
9 changes: 5 additions & 4 deletions tunnel_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -82,7 +83,7 @@ func TestTunnelRouteForIP(t *testing.T) {
}`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/ip/10.1.0.137", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/ip/"+url.PathEscape("10.1.0.137"), handler)

ts, _ := time.Parse(time.RFC3339Nano, "2021-01-25T18:22:34.317854Z")
want := TunnelRoute{
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestCreateTunnelRoute(t *testing.T) {
}`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/10.0.0.0/16", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/"+url.PathEscape("10.0.0.0/16"), handler)

ts, _ := time.Parse(time.RFC3339Nano, "2021-01-25T18:22:34.317854Z")
want := TunnelRoute{
Expand Down Expand Up @@ -184,7 +185,7 @@ func TestUpdateTunnelRoute(t *testing.T) {
VirtualNetworkID: "9f322de4-5988-4945-b770-f1d6ac200f86",
}

mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/10.0.0.0/16", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/"+url.PathEscape("10.0.0.0/16"), handler)
tunnel, err := client.UpdateTunnelRoute(context.Background(), AccountIdentifier(testAccountID), TunnelRoutesUpdateParams{TunnelID: testTunnelID, Network: "10.0.0.0/16", Comment: "foo", VirtualNetworkID: "9f322de4-5988-4945-b770-f1d6ac200f86"})

if assert.NoError(t, err) {
Expand Down Expand Up @@ -216,7 +217,7 @@ func TestDeleteTunnelRoute(t *testing.T) {
}`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/10.0.0.0/16", handler)
mux.HandleFunc("/accounts/"+testAccountID+"/teamnet/routes/network/"+url.PathEscape("10.0.0.0/16"), handler)
err := client.DeleteTunnelRoute(context.Background(), AccountIdentifier(testAccountID), TunnelRoutesDeleteParams{Network: "10.0.0.0/16", VirtualNetworkID: "9f322de4-5988-4945-b770-f1d6ac200f86"})
assert.NoError(t, err)
}
Loading