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

Function TestCmdExport

script/ghmock/export_test.go:56–332  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestCmdExport(t *testing.T) {
57 start := time.Date(2026, 11, 2, 20, 54, 40, 0, time.UTC)
58 const legacyRunJSON = `{
59 "id": "20261102T205540Z-bbbbbb",
60 "time": "2026-11-02T20:55:40Z",
61 "command": "ghmock run --gh ./bin/gh --terminal --keys {enter} -- repo create",
62 "results": [{
63 "binary": "./bin/gh",
64 "path": "/bin/gh",
65 "version": "gh version 1.0.0",
66 "exit_code": -1,
67 "terminal": true,
68 "waiting_for_input": true
69 }],
70 "report": "gh version 1.0.0 - /bin/gh\n$ gh repo create\nexit code: none, gh was still waiting for input, so ghmock stopped it\n"
71 }`
72 var legacyRun runRecord
73 require.NoError(t, json.Unmarshal([]byte(legacyRunJSON), &legacyRun))
74 require.Len(t, legacyRun.Results, 1)
75 assert.True(t, legacyRun.Results[0].Waiting)
76 runs := []runRecord{
77 {
78 ID: "20261102T205440Z-aaaaaa", Time: start, Command: "ghmock run --gh ./bin/gh -- issue view 1",
79 Schemas: []schemaFile{
80 {Name: "GraphQL schema", Path: "/cache/schema.docs.graphql", SHA256: "abc123"},
81 {Name: "REST description", Error: "downloads are off"},
82 },
83 Results: []runOutcome{{Binary: "./bin/gh", Path: "/bin/gh", Version: "gh version 1.0.0", Stdout: "title:\tBug\n"}},
84 Report: "gh version 1.0.0 - /bin/gh\n$ gh issue view 1\nexit code: 0\n",
85 },
86 legacyRun,
87 }
88 entries := []loggedRequest{
89 {Run: runs[0].ID, Binary: "./bin/gh", Seq: 1, Method: "POST", Name: "graphql IssueByNumber", Status: 200, Matched: true,
90 Response: 1, Responses: 1, ResponseBody: json.RawMessage(`{"data":{"repository":null}}`)},
91 {Run: runs[1].ID, Binary: "./bin/gh", Seq: 1, Method: "GET", Name: "GET /", Status: 404, ResponseRawBody: &[]byte{0, 255}},
92 }
93 responses := responseSet{
94 "graphql IssueByNumber": {{Body: json.RawMessage(`{"data":{"repository":null}}`), OffSchema: true}},
95 "GET /": {{Status: 401, RawBody: &[]byte{0, 255}}},
96 }
97 const wantReport = `### Run 20261102T205440Z-aaaaaa at 2026-11-02T20:54:40Z
98$ ghmock run --gh ./bin/gh -- issue view 1
99GraphQL schema: sha256 abc123, /cache/schema.docs.graphql
100REST description: not loaded, so not checked: downloads are off
101
102gh version 1.0.0 - /bin/gh
103$ gh issue view 1
104exit code: 0
105
106### Run 20261102T205540Z-bbbbbb at 2026-11-02T20:55:40Z
107$ ghmock run --gh ./bin/gh --terminal --keys {enter} -- repo create
108
109gh version 1.0.0 - /bin/gh
110$ gh repo create
111exit code: none, gh was still waiting for input, so ghmock stopped it
112`
113

Callers

nothing calls this directly

Calls 15

appendRunMethod · 0.95
appendLogMethod · 0.95
saveResponsesMethod · 0.95
gitFixtureDirMethod · 0.95
resetMethod · 0.95
readRunsMethod · 0.95
readLogMethod · 0.95
loadResponsesMethod · 0.95
prepareGitRepoFunction · 0.85
gitForTestFunction · 0.85
cmdWriteFunction · 0.85
cmdExportFunction · 0.85

Tested by

no test coverage detected