(t *testing.T)
| 94 | } |
| 95 | |
| 96 | func 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", |
nothing calls this directly
no test coverage detected