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