diff --git a/pkg/mockapi/api_server.go b/pkg/mockapi/api_server.go index 1e1f40e..a8758df 100644 --- a/pkg/mockapi/api_server.go +++ b/pkg/mockapi/api_server.go @@ -38,7 +38,7 @@ func NewHandler(t *testing.T) *Handler { }) h.Mux.Get("/users/me", h.handleUsersMe) - h.Mux.Get("/users/{id}/extended-access", h.handleUserExtendedAccess) + h.Mux.Get("/users/{user_id}/extended-access", h.handleUserExtendedAccess) h.Mux.Get("/ref/users", h.handleUserRefs) h.Mux.Post("/me/verification", func(w http.ResponseWriter, _ *http.Request) { _ = json.NewEncoder(w).Encode(map[string]any{"state": false, "type": ""}) @@ -46,28 +46,28 @@ func NewHandler(t *testing.T) *Handler { h.Mux.Get("/organizations", h.handleListOrgs) h.Mux.Post("/organizations", h.handleCreateOrg) - h.Mux.Get("/organizations/{id}", h.handleGetOrg) - h.Mux.Patch("/organizations/{id}", h.handlePatchOrg) - h.Mux.Get("/users/{id}/organizations", h.handleListOrgs) + h.Mux.Get("/organizations/{organization_id}", h.handleGetOrg) + h.Mux.Patch("/organizations/{organization_id}", h.handlePatchOrg) + h.Mux.Get("/users/{user_id}/organizations", h.handleListOrgs) h.Mux.Get("/ref/organizations", h.handleOrgRefs) - h.Mux.Post("/organizations/{id}/subscriptions", h.handleCreateSubscription) - h.Mux.Get("/subscriptions/{id}", h.handleGetSubscription) - h.Mux.Get("/organizations/{id}/subscriptions/can-create", h.handleCanCreateSubscriptions) - h.Mux.Get("/organizations/{id}/setup/options", func(w http.ResponseWriter, _ *http.Request) { + h.Mux.Post("/organizations/{organization_id}/subscriptions", h.handleCreateSubscription) + h.Mux.Get("/subscriptions/{subscription_id}", h.handleGetSubscription) + h.Mux.Get("/organizations/{organization_id}/subscriptions/can-create", h.handleCanCreateSubscriptions) + h.Mux.Get("/organizations/{organization_id}/setup/options", func(w http.ResponseWriter, _ *http.Request) { type options struct { Plans []string `json:"plans"` Regions []string `json:"regions"` } _ = json.NewEncoder(w).Encode(options{[]string{"development"}, []string{"test-region"}}) }) - h.Mux.Get("/organizations/{id}/subscriptions/estimate", func(w http.ResponseWriter, _ *http.Request) { + h.Mux.Get("/organizations/{organization_id}/subscriptions/estimate", func(w http.ResponseWriter, _ *http.Request) { _ = json.NewEncoder(w).Encode(map[string]any{"total": "$1,000 USD"}) }) - h.Mux.Get("/projects/{id}", h.handleGetProject) - h.Mux.Patch("/projects/{id}", h.handlePatchProject) - h.Mux.Get("/projects/{id}/environments", h.handleListEnvironments) + h.Mux.Get("/projects/{project_id}", h.handleGetProject) + h.Mux.Patch("/projects/{project_id}", h.handlePatchProject) + h.Mux.Get("/projects/{project_id}/environments", h.handleListEnvironments) h.Mux.Get("/projects/{project_id}/environments/{environment_id}", h.handleGetEnvironment) h.Mux.Get("/projects/{project_id}/environments/{environment_id}/backups", h.handleListBackups) h.Mux.Post("/projects/{project_id}/environments/{environment_id}/backups", h.handleCreateBackup) diff --git a/pkg/mockapi/environments.go b/pkg/mockapi/environments.go index d4a2ac4..1b6f22f 100644 --- a/pkg/mockapi/environments.go +++ b/pkg/mockapi/environments.go @@ -15,7 +15,7 @@ import ( func (h *Handler) handleListEnvironments(w http.ResponseWriter, req *http.Request) { h.store.RLock() defer h.store.RUnlock() - projectID := chi.URLParam(req, "id") + projectID := chi.URLParam(req, "project_id") var envs []*Environment for _, e := range h.store.environments { if e.Project == projectID { diff --git a/pkg/mockapi/orgs.go b/pkg/mockapi/orgs.go index 98be492..a3077ad 100644 --- a/pkg/mockapi/orgs.go +++ b/pkg/mockapi/orgs.go @@ -56,7 +56,7 @@ func (h *Handler) handleGetOrg(w http.ResponseWriter, req *http.Request) { defer h.store.RUnlock() var org *Org - orgID := chi.URLParam(req, "id") + orgID := chi.URLParam(req, "organization_id") if strings.HasPrefix(orgID, "name%3D") { name := strings.TrimPrefix(orgID, "name%3D") for _, o := range h.store.orgs { @@ -103,8 +103,8 @@ func (h *Handler) handleCreateOrg(w http.ResponseWriter, req *http.Request) { func (h *Handler) handlePatchOrg(w http.ResponseWriter, req *http.Request) { h.store.Lock() defer h.store.Unlock() - projectID := chi.URLParam(req, "id") - p, ok := h.store.orgs[projectID] + orgID := chi.URLParam(req, "organization_id") + p, ok := h.store.orgs[orgID] if !ok { w.WriteHeader(http.StatusNotFound) return @@ -115,6 +115,6 @@ func (h *Handler) handlePatchOrg(w http.ResponseWriter, req *http.Request) { w.WriteHeader(http.StatusBadRequest) return } - h.store.orgs[projectID] = &patched + h.store.orgs[orgID] = &patched _ = json.NewEncoder(w).Encode(&patched) } diff --git a/pkg/mockapi/projects.go b/pkg/mockapi/projects.go index a12a44c..d731eb0 100644 --- a/pkg/mockapi/projects.go +++ b/pkg/mockapi/projects.go @@ -29,7 +29,7 @@ func (h *Handler) handleProjectRefs(w http.ResponseWriter, req *http.Request) { func (h *Handler) handleGetProject(w http.ResponseWriter, req *http.Request) { h.store.RLock() defer h.store.RUnlock() - projectID := chi.URLParam(req, "id") + projectID := chi.URLParam(req, "project_id") if p, ok := h.store.projects[projectID]; ok { _ = json.NewEncoder(w).Encode(p) return @@ -40,7 +40,7 @@ func (h *Handler) handleGetProject(w http.ResponseWriter, req *http.Request) { func (h *Handler) handlePatchProject(w http.ResponseWriter, req *http.Request) { h.store.Lock() defer h.store.Unlock() - projectID := chi.URLParam(req, "id") + projectID := chi.URLParam(req, "project_id") p, ok := h.store.projects[projectID] if !ok { w.WriteHeader(http.StatusNotFound) diff --git a/pkg/mockapi/subscriptions.go b/pkg/mockapi/subscriptions.go index d04d577..290f1a4 100644 --- a/pkg/mockapi/subscriptions.go +++ b/pkg/mockapi/subscriptions.go @@ -42,7 +42,7 @@ func (h *Handler) handleCreateSubscription(w http.ResponseWriter, req *http.Requ Links: MakeHALLinks("self=/projects/" + projectID), Repository: ProjectRepository{URL: projectID + "@git.example.com:" + projectID + ".git"}, SubscriptionID: sub.ID, - Organization: chi.URLParam(req, "id"), + Organization: chi.URLParam(req, "organization_id"), } h.store.Unlock() @@ -63,7 +63,7 @@ func (h *Handler) handleCreateSubscription(w http.ResponseWriter, req *http.Requ func (h *Handler) handleGetSubscription(w http.ResponseWriter, req *http.Request) { h.store.RLock() defer h.store.RUnlock() - id := chi.URLParam(req, "id") + id := chi.URLParam(req, "subscription_id") sub := h.store.subscriptions[id] if sub == nil { w.WriteHeader(http.StatusNotFound) @@ -75,7 +75,7 @@ func (h *Handler) handleGetSubscription(w http.ResponseWriter, req *http.Request func (h *Handler) handleCanCreateSubscriptions(w http.ResponseWriter, req *http.Request) { h.store.RLock() defer h.store.RUnlock() - id := chi.URLParam(req, "id") + id := chi.URLParam(req, "organization_id") cc := h.store.canCreate[id] if cc == nil { cc = &CanCreateResponse{CanCreate: true} diff --git a/pkg/mockapi/users.go b/pkg/mockapi/users.go index 2e60092..4d27ed6 100644 --- a/pkg/mockapi/users.go +++ b/pkg/mockapi/users.go @@ -26,7 +26,7 @@ func (h *Handler) handleUserRefs(w http.ResponseWriter, req *http.Request) { func (h *Handler) handleUserExtendedAccess(w http.ResponseWriter, req *http.Request) { h.store.RLock() defer h.store.RUnlock() - userID := chi.URLParam(req, "id") + userID := chi.URLParam(req, "user_id") require.NoError(h.t, req.ParseForm()) require.Equal(h.t, "project", req.Form.Get("filter[resource_type]")) var (