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

Function assertProduce

coderd/coderdtest/swaggerparser.go:389–415  ·  view source on GitHub ↗
(t *testing.T, comment SwaggerComment)

Source from the content-addressed store, hash-verified

387var allowedProduceTypes = []string{"json", "text/event-stream", "text/html", "text/plain"}
388
389func assertProduce(t *testing.T, comment SwaggerComment) {
390 var hasResponseModel bool
391 for _, r := range comment.successes {
392 if r.model != "" {
393 hasResponseModel = true
394 break
395 }
396 }
397
398 if hasResponseModel {
399 assert.True(t, comment.produce != "", "Route must have @Produce annotation as it responds with a model structure")
400 assert.Contains(t, allowedProduceTypes, comment.produce, "@Produce value is limited to specific types: %s", strings.Join(allowedProduceTypes, ","))
401 } else {
402 if (comment.router == "/api/v2/workspaceagents/me/app-health" && comment.method == "post") ||
403 (comment.router == "/api/v2/workspaceagents/me/startup" && comment.method == "post") ||
404 (comment.router == "/api/v2/workspaceagents/me/startup/logs" && comment.method == "patch") ||
405 (comment.router == "/api/v2/licenses/{id}" && comment.method == "delete") ||
406 (comment.router == "/api/v2/debug/coordinator" && comment.method == "get") ||
407 (comment.router == "/api/v2/debug/tailnet" && comment.method == "get") ||
408 (comment.router == "/api/v2/workspaces/{workspace}/acl" && comment.method == "patch") ||
409 (comment.router == "/api/v2/init-script/{os}/{arch}" && comment.method == "get") {
410 return // Exception: HTTP 200 is returned without response entity
411 }
412
413 assert.Truef(t, comment.produce == "", "Response model is undefined, so we can't predict the content type: %v", comment)
414 }
415}

Callers 1

VerifySwaggerDefinitionsFunction · 0.85

Calls 1

ContainsMethod · 0.45

Tested by

no test coverage detected