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

Function TestAPI_PostWithStdinInput

cli/cmd/api/api_test.go:108–131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

106}
107
108func TestAPI_PostWithStdinInput(t *testing.T) {
109 _, _ = iostreams.SetForTest(t)
110 var seenBody []byte
111 var seenMethod, seenPath string
112 cli, stop := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
113 seenMethod = r.Method
114 seenPath = r.URL.Path
115 seenBody, _ = io.ReadAll(r.Body)
116 w.Header().Set("Content-Type", "application/json")
117 _, _ = w.Write([]byte(`{"id":"new"}`))
118 })
119 defer stop()
120
121 opts := &Options{Input: "-", StdinReader: strings.NewReader(`{"name":"foo"}`)}
122 if err := runAPI(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, cli, "POST", "/api/v1/things", false); err != nil {
123 t.Fatalf("runAPI: %v", err)
124 }
125 if seenMethod != http.MethodPost || seenPath != "/api/v1/things" {
126 t.Errorf("server saw %s %s, want POST /api/v1/things", seenMethod, seenPath)
127 }
128 if string(seenBody) != `{"name":"foo"}` {
129 t.Errorf("server received body %q, want %q", seenBody, `{"name":"foo"}`)
130 }
131}
132
133// TestAPI_InputFile verifies --input <file> reads the request body from disk.
134func TestAPI_InputFile(t *testing.T) {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected