newServer spins up a dashboard stub. An empty userJSON makes /1/user fail.
(t *testing.T, userJSON string)
| 148 | |
| 149 | // newServer spins up a dashboard stub. An empty userJSON makes /1/user fail. |
| 150 | func newServer(t *testing.T, userJSON string) *createServer { |
| 151 | t.Helper() |
| 152 | srv := &createServer{} |
| 153 | |
| 154 | appResponse := dashboard.SingleApplicationResponse{ |
| 155 | Data: dashboard.ApplicationResource{ |
| 156 | ID: "APP1", |
| 157 | Type: "application", |
| 158 | Attributes: dashboard.ApplicationAttributes{ |
| 159 | ApplicationID: "APP1", |
| 160 | Name: "My App", |
| 161 | }, |
| 162 | }, |
| 163 | } |
| 164 | |
| 165 | mux := http.NewServeMux() |
| 166 | mux.HandleFunc( |
| 167 | "/1/plan-templates/self-serve", |
| 168 | func(w http.ResponseWriter, _ *http.Request) { |
| 169 | templates := samplePlanTemplates() |
| 170 | if srv.freeOnly { |
| 171 | templates = templates[:1] // only the free "build" template |
| 172 | } |
| 173 | require.NoError(t, json.NewEncoder(w).Encode(dashboard.PlanTemplatesResponse{ |
| 174 | Data: templates, |
| 175 | })) |
| 176 | }, |
| 177 | ) |
| 178 | mux.HandleFunc("/1/user", func(w http.ResponseWriter, _ *http.Request) { |
| 179 | if userJSON == "" { |
| 180 | w.WriteHeader(http.StatusInternalServerError) |
| 181 | return |
| 182 | } |
| 183 | require.NoError(t, json.NewEncoder(w).Encode(json.RawMessage(userJSON))) |
| 184 | }) |
| 185 | mux.HandleFunc("/1/hosting/regions", func(w http.ResponseWriter, _ *http.Request) { |
| 186 | require.NoError(t, json.NewEncoder(w).Encode(dashboard.RegionsResponse{ |
| 187 | RegionCodes: []dashboard.Region{{Code: "CA", Name: "Canada"}}, |
| 188 | })) |
| 189 | }) |
| 190 | mux.HandleFunc("/1/applications", func(w http.ResponseWriter, r *http.Request) { |
| 191 | if r.Method != http.MethodPost { |
| 192 | w.WriteHeader(http.StatusNotFound) |
| 193 | return |
| 194 | } |
| 195 | srv.createCalls++ |
| 196 | require.NoError(t, json.NewEncoder(w).Encode(appResponse)) |
| 197 | }) |
| 198 | mux.HandleFunc( |
| 199 | "/1/applications/APP1/api-keys", |
| 200 | func(w http.ResponseWriter, _ *http.Request) { |
| 201 | require.NoError(t, json.NewEncoder(w).Encode(dashboard.CreateAPIKeyResponse{ |
| 202 | Data: dashboard.APIKeyResource{ |
| 203 | ID: "key", |
| 204 | Type: "key", |
| 205 | Attributes: dashboard.APIKeyAttributes{Value: "test-api-key"}, |
| 206 | }, |
| 207 | })) |
no test coverage detected