(t *testing.T)
| 119 | } |
| 120 | |
| 121 | func Test_deleteRun(t *testing.T) { |
| 122 | tests := []struct { |
| 123 | name string |
| 124 | opts *DeleteOptions |
| 125 | cancel bool |
| 126 | httpStubs func(*httpmock.Registry) |
| 127 | mockPromptGists bool |
| 128 | noGists bool |
| 129 | wantErr bool |
| 130 | wantStdout string |
| 131 | wantStderr string |
| 132 | }{ |
| 133 | { |
| 134 | name: "successfully delete", |
| 135 | opts: &DeleteOptions{ |
| 136 | Selector: "1234", |
| 137 | }, |
| 138 | httpStubs: func(reg *httpmock.Registry) { |
| 139 | reg.Register(httpmock.REST("GET", "gists/1234"), |
| 140 | httpmock.JSONResponse(shared.Gist{ID: "1234", Files: map[string]*shared.GistFile{"cool.txt": {Filename: "cool.txt"}}})) |
| 141 | reg.Register(httpmock.REST("DELETE", "gists/1234"), |
| 142 | httpmock.StatusStringResponse(200, "{}")) |
| 143 | }, |
| 144 | wantStdout: "✓ Gist \"cool.txt\" deleted\n", |
| 145 | }, |
| 146 | { |
| 147 | name: "successfully delete with prompt", |
| 148 | opts: &DeleteOptions{ |
| 149 | Selector: "", |
| 150 | }, |
| 151 | httpStubs: func(reg *httpmock.Registry) { |
| 152 | reg.Register(httpmock.REST("DELETE", "gists/1234"), |
| 153 | httpmock.StatusStringResponse(200, "{}")) |
| 154 | }, |
| 155 | mockPromptGists: true, |
| 156 | wantStdout: "✓ Gist \"cool.txt\" deleted\n", |
| 157 | }, |
| 158 | { |
| 159 | name: "successfully delete with --yes", |
| 160 | opts: &DeleteOptions{ |
| 161 | Selector: "1234", |
| 162 | Confirmed: true, |
| 163 | }, |
| 164 | httpStubs: func(reg *httpmock.Registry) { |
| 165 | reg.Register(httpmock.REST("GET", "gists/1234"), |
| 166 | httpmock.JSONResponse(shared.Gist{ID: "1234", Files: map[string]*shared.GistFile{"cool.txt": {Filename: "cool.txt"}}})) |
| 167 | reg.Register(httpmock.REST("DELETE", "gists/1234"), |
| 168 | httpmock.StatusStringResponse(200, "{}")) |
| 169 | }, |
| 170 | wantStdout: "✓ Gist \"cool.txt\" deleted\n", |
| 171 | }, |
| 172 | { |
| 173 | name: "successfully delete with prompt and --yes", |
| 174 | opts: &DeleteOptions{ |
| 175 | Selector: "", |
| 176 | Confirmed: true, |
| 177 | }, |
| 178 | httpStubs: func(reg *httpmock.Registry) { |
nothing calls this directly
no test coverage detected