(t *testing.T)
| 138 | } |
| 139 | |
| 140 | func Test_editRun(t *testing.T) { |
| 141 | fileToAdd := filepath.Join(t.TempDir(), "gist-test.txt") |
| 142 | err := os.WriteFile(fileToAdd, []byte("hello"), 0600) |
| 143 | require.NoError(t, err) |
| 144 | |
| 145 | tests := []struct { |
| 146 | name string |
| 147 | opts *EditOptions |
| 148 | mockGist *shared.Gist |
| 149 | mockGistList bool |
| 150 | httpStubs func(*httpmock.Registry) |
| 151 | prompterStubs func(*prompter.MockPrompter) |
| 152 | isTTY bool |
| 153 | stdin string |
| 154 | wantErr string |
| 155 | wantLastRequestParameters map[string]interface{} |
| 156 | }{ |
| 157 | { |
| 158 | name: "no such gist", |
| 159 | wantErr: "gist not found: 1234", |
| 160 | opts: &EditOptions{ |
| 161 | Selector: "1234", |
| 162 | }, |
| 163 | }, |
| 164 | { |
| 165 | name: "one file", |
| 166 | isTTY: false, |
| 167 | opts: &EditOptions{ |
| 168 | Selector: "1234", |
| 169 | }, |
| 170 | mockGist: &shared.Gist{ |
| 171 | ID: "1234", |
| 172 | Files: map[string]*shared.GistFile{ |
| 173 | "cicada.txt": { |
| 174 | Filename: "cicada.txt", |
| 175 | Content: "bwhiizzzbwhuiiizzzz", |
| 176 | Type: "text/plain", |
| 177 | }, |
| 178 | }, |
| 179 | Owner: &shared.GistOwner{Login: "octocat"}, |
| 180 | }, |
| 181 | httpStubs: func(reg *httpmock.Registry) { |
| 182 | reg.Register(httpmock.REST("POST", "gists/1234"), |
| 183 | httpmock.StatusStringResponse(201, "{}")) |
| 184 | }, |
| 185 | wantLastRequestParameters: map[string]interface{}{ |
| 186 | "description": "", |
| 187 | "files": map[string]interface{}{ |
| 188 | "cicada.txt": map[string]interface{}{ |
| 189 | "content": "new file content", |
| 190 | "filename": "cicada.txt", |
| 191 | }, |
| 192 | }, |
| 193 | }, |
| 194 | }, |
| 195 | { |
| 196 | name: "multiple files, submit, with TTY", |
| 197 | isTTY: true, |
nothing calls this directly
no test coverage detected