MCPcopy Index your code
hub / github.com/coder/coder / TestSwagger

Function TestSwagger

coderd/coderd_test.go:263–351  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

261}
262
263func TestSwagger(t *testing.T) {
264 t.Parallel()
265
266 const swaggerEndpoint = "/swagger"
267 t.Run("endpoint enabled", func(t *testing.T) {
268 t.Parallel()
269
270 client := coderdtest.New(t, &coderdtest.Options{
271 SwaggerEndpoint: true,
272 })
273
274 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
275 defer cancel()
276
277 resp, err := requestWithRetries(ctx, t, client, http.MethodGet, swaggerEndpoint, nil)
278 require.NoError(t, err)
279
280 body, err := io.ReadAll(resp.Body)
281 require.NoError(t, err)
282 defer resp.Body.Close()
283
284 bodyString := string(body)
285 require.Contains(t, bodyString, "Swagger UI")
286 require.Contains(t, bodyString, "requestInterceptor")
287 })
288 t.Run("doc.json exposed", func(t *testing.T) {
289 t.Parallel()
290
291 client := coderdtest.New(t, &coderdtest.Options{
292 SwaggerEndpoint: true,
293 })
294
295 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
296 defer cancel()
297
298 resp, err := requestWithRetries(ctx, t, client, http.MethodGet, swaggerEndpoint+"/doc.json", nil)
299 require.NoError(t, err)
300
301 body, err := io.ReadAll(resp.Body)
302 require.NoError(t, err)
303 defer resp.Body.Close()
304
305 bodyString := string(body)
306 require.NotContains(t, bodyString, `"/api/v2/scim/v2`)
307
308 var doc struct {
309 Swagger string `json:"swagger"`
310 BasePath string `json:"basePath"`
311 Paths map[string]map[string]json.RawMessage `json:"paths"`
312 }
313 require.NoError(t, json.Unmarshal(body, &doc))
314 require.Equal(t, "2.0", doc.Swagger)
315 require.Equal(t, "/", doc.BasePath)
316 require.Contains(t, doc.Paths, "/api/v2/users")
317 require.Contains(t, doc.Paths, "/api/v2/oauth2-provider/apps")
318 require.Contains(t, doc.Paths, "/api/experimental/watch-all-workspacebuilds")
319 require.Contains(t, doc.Paths, "/.well-known/oauth-authorization-server")
320 require.Contains(t, doc.Paths, "/oauth2/tokens")

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
requestWithRetriesFunction · 0.70
RunMethod · 0.65
CloseMethod · 0.65
ReadAllMethod · 0.45
ContainsMethod · 0.45
UnmarshalMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected