MCPcopy
hub / github.com/cli/cli / TestPromptGists

Function TestPromptGists

pkg/cmd/gist/shared/shared_test.go:95–221  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestPromptGists(t *testing.T) {
96 sixHours, _ := time.ParseDuration("6h")
97 sixHoursAgo := time.Now().Add(-sixHours)
98 sixHoursAgoFormatted := sixHoursAgo.Format(time.RFC3339Nano)
99
100 tests := []struct {
101 name string
102 prompterStubs func(pm *prompter.MockPrompter)
103 response string
104 wantOut Gist
105 wantErr bool
106 }{
107 {
108 name: "multiple files, select first gist",
109 prompterStubs: func(pm *prompter.MockPrompter) {
110 pm.RegisterSelect("Select a gist",
111 []string{"cool.txt about 6 hours ago", "gistfile0.txt about 6 hours ago"},
112 func(_, _ string, opts []string) (int, error) {
113 return prompter.IndexFor(opts, "cool.txt about 6 hours ago")
114 })
115 },
116 response: `{ "data": { "viewer": { "gists": { "nodes": [
117 {
118 "name": "1234",
119 "files": [{ "name": "cool.txt" }],
120 "description": "",
121 "updatedAt": "%[1]v",
122 "isPublic": true
123 },
124 {
125 "name": "5678",
126 "files": [{ "name": "gistfile0.txt" }],
127 "description": "",
128 "updatedAt": "%[1]v",
129 "isPublic": true
130 }
131 ] } } } }`,
132 wantOut: Gist{ID: "1234", Files: map[string]*GistFile{"cool.txt": {Filename: "cool.txt"}}, UpdatedAt: sixHoursAgo, Public: true},
133 },
134 {
135 name: "multiple files, select second gist",
136 prompterStubs: func(pm *prompter.MockPrompter) {
137 pm.RegisterSelect("Select a gist",
138 []string{"cool.txt about 6 hours ago", "gistfile0.txt about 6 hours ago"},
139 func(_, _ string, opts []string) (int, error) {
140 return prompter.IndexFor(opts, "gistfile0.txt about 6 hours ago")
141 })
142 },
143 response: `{ "data": { "viewer": { "gists": { "nodes": [
144 {
145 "name": "1234",
146 "files": [{ "name": "cool.txt" }],
147 "description": "",
148 "updatedAt": "%[1]v",
149 "isPublic": true
150 },
151 {
152 "name": "5678",

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
VerifyMethod · 0.95
IndexForFunction · 0.92
TestFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
NewMockPrompterFunction · 0.92
PromptGistsFunction · 0.85
ColorSchemeMethod · 0.80
EqualMethod · 0.80
AddMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected