Skip to content

Commit

Permalink
mockapi: clarify parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Dec 12, 2024
1 parent 789668d commit 1173673
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
24 changes: 12 additions & 12 deletions pkg/mockapi/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,36 @@ 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": ""})
})

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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/mockapi/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/mockapi/orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/mockapi/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/mockapi/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mockapi/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 1173673

Please sign in to comment.