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

Function TestPromptGists

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

Source from the content-addressed store, hash-verified

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