MCPcopy Index your code
hub / github.com/Tencent/WeKnora / TestAPI_InputFile

Function TestAPI_InputFile

cli/cmd/api/api_test.go:134–155  ·  view source on GitHub ↗

TestAPI_InputFile verifies --input reads the request body from disk.

(t *testing.T)

Source from the content-addressed store, hash-verified

132
133// TestAPI_InputFile verifies --input <file> reads the request body from disk.
134func TestAPI_InputFile(t *testing.T) {
135 _, _ = iostreams.SetForTest(t)
136 tmp := filepath.Join(t.TempDir(), "body.json")
137 payload := `{"k":"from-file"}`
138 if err := os.WriteFile(tmp, []byte(payload), 0o600); err != nil {
139 t.Fatalf("write temp: %v", err)
140 }
141 var seenBody []byte
142 cli, stop := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
143 seenBody, _ = io.ReadAll(r.Body)
144 _, _ = w.Write([]byte(`{}`))
145 })
146 defer stop()
147
148 opts := &Options{Input: tmp}
149 if err := runAPI(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, cli, "POST", "/api/v1/x", false); err != nil {
150 t.Fatalf("runAPI: %v", err)
151 }
152 if string(seenBody) != payload {
153 t.Errorf("body from --input: got %q, want %q", seenBody, payload)
154 }
155}
156
157// TestAPI_InputDash_Stdin verifies the "--input -" form: the payload comes
158// from opts.StdinReader (production-default iostreams.IO.In).

Callers

nothing calls this directly

Calls 5

SetForTestFunction · 0.92
stopFunction · 0.85
runAPIFunction · 0.85
WriteMethod · 0.80
newTestClientFunction · 0.70

Tested by

no test coverage detected