MCPcopy Create free account
hub / github.com/diillson/chatcli / TestParseHTTPInvocation_FlagArgv

Function TestParseHTTPInvocation_FlagArgv

cli/plugins/argv_flatten_parse_test.go:21–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestParseHTTPInvocation_FlagArgv(t *testing.T) {
22 // {"cmd":"get","args":{"url":"https://api.github.com/zen"}}
23 in, err := parseHTTPInvocation([]string{"get", "--url", "https://api.github.com/zen"})
24 if err != nil {
25 t.Fatalf("get: %v", err)
26 }
27 if in.Method != "GET" || in.URL != "https://api.github.com/zen" {
28 t.Fatalf("get parsed (%q,%q)", in.Method, in.URL)
29 }
30
31 // {"cmd":"request","args":{"method":"POST","url":"...","body":"{\"a\":1}","headers":{"X-Token":"t"},"timeout_seconds":30}}
32 in, err = parseHTTPInvocation([]string{
33 "request",
34 "--body", `{"a":1}`,
35 "--headers", `{"X-Token":"t"}`,
36 "--method", "POST",
37 "--timeout_seconds", "30",
38 "--url", "https://api.example.com/v1",
39 })
40 if err != nil {
41 t.Fatalf("request: %v", err)
42 }
43 if in.Method != "POST" || in.URL != "https://api.example.com/v1" || in.Body != `{"a":1}` {
44 t.Fatalf("request parsed (%q,%q,%q)", in.Method, in.URL, in.Body)
45 }
46 if in.Headers["X-Token"] != "t" {
47 t.Fatalf("headers not decoded from stringified object: %+v", in.Headers)
48 }
49 if in.TimeoutSeconds != 30 {
50 t.Fatalf("timeout_seconds = %d, want 30", in.TimeoutSeconds)
51 }
52
53 // Legacy positional forms must keep working.
54 in, err = parseHTTPInvocation([]string{"get", "https://api.github.com/zen"})
55 if err != nil || in.URL != "https://api.github.com/zen" {
56 t.Fatalf("positional get: %v (%q)", err, in.URL)
57 }
58 in, err = parseHTTPInvocation([]string{"request", "GET", "https://api.github.com/zen"})
59 if err != nil || in.Method != "GET" || in.URL != "https://api.github.com/zen" {
60 t.Fatalf("positional request: %v (%q,%q)", err, in.Method, in.URL)
61 }
62}
63
64func TestParseLSPInvocation_FlagArgv(t *testing.T) {
65 // {"cmd":"definition","args":{"file":"cli/cli.go","line":128,"column":14}}

Callers

nothing calls this directly

Calls 1

parseHTTPInvocationFunction · 0.85

Tested by

no test coverage detected