MCPcopy Create free account
hub / github.com/coder/agentapi / TestOpenAPISchema

Function TestOpenAPISchema

lib/httpapi/server_test.go:27–64  ·  view source on GitHub ↗

Ensure the OpenAPI schema on disk is up to date. To update the schema, run `go run main.go server --print-openapi dummy > openapi.json`.

(t *testing.T)

Source from the content-addressed store, hash-verified

25// Ensure the OpenAPI schema on disk is up to date.
26// To update the schema, run `go run main.go server --print-openapi dummy > openapi.json`.
27func TestOpenAPISchema(t *testing.T) {
28 t.Parallel()
29
30 ctx := logctx.WithLogger(context.Background(), slog.New(slog.NewTextHandler(os.Stdout, nil)))
31 srv, err := httpapi.NewServer(ctx, httpapi.ServerConfig{
32 AgentType: msgfmt.AgentTypeClaude,
33 AgentIO: nil,
34 Port: 0,
35 ChatBasePath: "/chat",
36 AllowedHosts: []string{"*"},
37 AllowedOrigins: []string{"*"},
38 })
39 require.NoError(t, err)
40 currentSchemaStr := srv.GetOpenAPI()
41 var currentSchema any
42 if err := json.Unmarshal([]byte(currentSchemaStr), &currentSchema); err != nil {
43 t.Fatalf("failed to unmarshal current schema: %s", err)
44 }
45
46 diskSchemaFile, err := os.OpenFile("../../openapi.json", os.O_RDONLY, 0)
47 if err != nil {
48 t.Fatalf("failed to open disk schema: %s", err)
49 }
50 defer func() {
51 _ = diskSchemaFile.Close()
52 }()
53
54 diskSchemaBytes, err := io.ReadAll(diskSchemaFile)
55 if err != nil {
56 t.Fatalf("failed to read disk schema: %s", err)
57 }
58 var diskSchema any
59 if err := json.Unmarshal(diskSchemaBytes, &diskSchema); err != nil {
60 t.Fatalf("failed to unmarshal disk schema: %s", err)
61 }
62
63 require.Equal(t, currentSchema, diskSchema)
64}
65
66func TestServer_redirectToChat(t *testing.T) {
67 cases := []struct {

Callers

nothing calls this directly

Calls 4

GetOpenAPIMethod · 0.95
WithLoggerFunction · 0.92
NewServerFunction · 0.92
CloseMethod · 0.80

Tested by

no test coverage detected