MCPcopy Create free account
hub / github.com/cli/cli / TestCmdSet

Function TestCmdSet

script/ghmock/set_test.go:342–663  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

340}
341
342func TestCmdSet(t *testing.T) {
343 const issueQuery = `query IssueTitle { repository(owner: "o", name: "r") { issue(number: 1) { title state } } }`
344 logged := []loggedRequest{{
345 Run: "r", Seq: 1, Method: "POST", Host: apiHost, Path: "/graphql", Name: "graphql IssueTitle",
346 GraphQL: &graphQLRequest{Kind: "query", Operation: "IssueTitle", Query: issueQuery},
347 }}
348 const validIssue = `{"id":1,"number":1,"title":"Bug","state":"open","user":null,"labels":[],"created_at":"2026-01-01T00:00:00Z"}`
349 const validTitle = `{"data":{"repository":{"issue":{"title":"Bug","state":"OPEN"}}}}`
350 const badTitle = `{"data":{"repository":{"issue":{"title":"Bug","state":"open"}}}}`
351
352 tests := []struct {
353 name string
354 noSchemas bool
355 responses string
356 logged []loggedRequest
357 args []string
358 files map[string][]byte
359 symlink bool
360 check func(*testing.T, responseSet)
361 wantStdout string
362 wantErr string
363 want string
364 }{
365 {
366 name: "response-only saves retain unknown conditional selections",
367 logged: []loggedRequest{{
368 Run: "r", Seq: 1, Method: "POST", Host: apiHost, Path: "/graphql", Name: "graphql Conditional",
369 GraphQL: &graphQLRequest{Kind: "query", Operation: "Conditional", Query: `query Conditional($x:Boolean!) { viewer { login } viewer @include(if:$x) { name } }`},
370 }},
371 args: []string{"graphql Conditional", "--body", `{"data":{"viewer":{"login":"monalisa"}}}`},
372 wantStdout: "graphql Conditional: response 1 of 1: status 200, no headers, body 40 bytes\nSchema check: passed\n",
373 want: `{"graphql Conditional":[{"body":{"data":{"viewer":{"login":"monalisa"}}}}]}`,
374 },
375 {
376 name: "response-only saves do not assume an operation default was used",
377 logged: []loggedRequest{{
378 Run: "r", Seq: 1, Method: "POST", Host: apiHost, Path: "/graphql", Name: "graphql Conditional",
379 GraphQL: &graphQLRequest{Kind: "query", Operation: "Conditional", Query: `query Conditional($x:Boolean = true) { viewer { login } viewer @include(if:$x) { name } }`},
380 }},
381 args: []string{"graphql Conditional", "--body", `{"data":{"viewer":{"login":"monalisa"}}}`},
382 wantStdout: "graphql Conditional: response 1 of 1: status 200, no headers, body 40 bytes\nSchema check: passed\n",
383 want: `{"graphql Conditional":[{"body":{"data":{"viewer":{"login":"monalisa"}}}}]}`,
384 },
385 {
386 name: "response-only saves select the named operation",
387 logged: []loggedRequest{{
388 Run: "r", Seq: 1, Method: "POST", Host: apiHost, Path: "/graphql", Name: "graphql IssueTitle",
389 GraphQL: &graphQLRequest{Kind: "query", Operation: "IssueTitle", Query: `query Other { viewer { login } } ` + issueQuery},
390 }},
391 args: []string{"graphql IssueTitle", "--body", validTitle},
392 wantStdout: fmt.Sprintf("graphql IssueTitle: response 1 of 1: status 200, no headers, body %d bytes\nSchema check: passed\n", len(validTitle)),
393 want: `{"graphql IssueTitle":[{"body":` + validTitle + `}]}`,
394 },
395 {
396 name: "raw files preserve arbitrary bytes",
397 args: []string{"GET /binary", "--raw-file", "<files>/body.bin"},
398 files: map[string][]byte{"body.bin": {0, 255}},
399 wantStdout: "GET /binary: response 1 of 1: status 200, no headers, body 2 bytes, raw\nSchema check: passed\n",

Callers

nothing calls this directly

Calls 15

saveResponsesMethod · 0.95
appendLogMethod · 0.95
loadResponsesMethod · 0.95
useTestSchemasFunction · 0.85
cmdSetFunction · 0.85
EqualMethod · 0.80
OpenMethod · 0.80
JoinMethod · 0.80
MkdirAllMethod · 0.80
WriteFileMethod · 0.80
SkipMethod · 0.80
ContainsMethod · 0.80

Tested by

no test coverage detected