MCPcopy
hub / github.com/Tencent/WeKnora / TestAPI_GetSuccess

Function TestAPI_GetSuccess

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

Source from the content-addressed store, hash-verified

43}
44
45func TestAPI_GetSuccess(t *testing.T) {
46 out, _ := iostreams.SetForTest(t)
47 cli, stop := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
48 if r.Method != http.MethodGet || r.URL.Path != "/api/v1/foo" {
49 t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path)
50 }
51 w.Header().Set("Content-Type", "application/json")
52 _, _ = w.Write([]byte(`{"hello":"world"}`))
53 })
54 defer stop()
55
56 if err := runAPI(context.Background(), &Options{}, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, cli, "GET", "/api/v1/foo", false); err != nil {
57 t.Fatalf("runAPI: %v", err)
58 }
59 got := out.String()
60 if !strings.Contains(got, `"hello":"world"`) {
61 t.Errorf("expected raw JSON body in stdout, got %q", got)
62 }
63 if !strings.HasSuffix(got, "\n") {
64 t.Errorf("expected trailing newline appended, got %q", got)
65 }
66}
67
68func TestAPI_GetSuccess_JSON(t *testing.T) {
69 out, _ := iostreams.SetForTest(t)

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected