(t *testing.T)
| 120 | } |
| 121 | |
| 122 | func TestDeleteRun(t *testing.T) { |
| 123 | tests := []struct { |
| 124 | name string |
| 125 | opts DeleteOptions |
| 126 | stubs func(*httpmock.Registry) |
| 127 | tty bool |
| 128 | wantErr bool |
| 129 | wantErrMsg string |
| 130 | wantStderr string |
| 131 | wantStdout string |
| 132 | }{ |
| 133 | { |
| 134 | name: "deletes cache tty", |
| 135 | opts: DeleteOptions{Identifier: "123"}, |
| 136 | stubs: func(reg *httpmock.Registry) { |
| 137 | reg.Register( |
| 138 | httpmock.REST("DELETE", "repos/OWNER/REPO/actions/caches/123"), |
| 139 | httpmock.StatusStringResponse(204, ""), |
| 140 | ) |
| 141 | }, |
| 142 | tty: true, |
| 143 | wantStdout: "✓ Deleted 1 cache from OWNER/REPO\n", |
| 144 | }, |
| 145 | { |
| 146 | name: "deletes cache notty", |
| 147 | opts: DeleteOptions{Identifier: "123"}, |
| 148 | stubs: func(reg *httpmock.Registry) { |
| 149 | reg.Register( |
| 150 | httpmock.REST("DELETE", "repos/OWNER/REPO/actions/caches/123"), |
| 151 | httpmock.StatusStringResponse(204, ""), |
| 152 | ) |
| 153 | }, |
| 154 | tty: false, |
| 155 | wantStdout: "", |
| 156 | }, |
| 157 | { |
| 158 | name: "non-existent cache", |
| 159 | opts: DeleteOptions{Identifier: "123"}, |
| 160 | stubs: func(reg *httpmock.Registry) { |
| 161 | reg.Register( |
| 162 | httpmock.REST("DELETE", "repos/OWNER/REPO/actions/caches/123"), |
| 163 | httpmock.StatusStringResponse(404, ""), |
| 164 | ) |
| 165 | }, |
| 166 | wantErr: true, |
| 167 | wantErrMsg: "X Could not find a cache matching 123 in OWNER/REPO", |
| 168 | }, |
| 169 | { |
| 170 | name: "deletes all caches", |
| 171 | opts: DeleteOptions{DeleteAll: true}, |
| 172 | stubs: func(reg *httpmock.Registry) { |
| 173 | reg.Register( |
| 174 | httpmock.REST("GET", "repos/OWNER/REPO/actions/caches"), |
| 175 | httpmock.JSONResponse(shared.CachePayload{ |
| 176 | ActionsCaches: []shared.Cache{ |
| 177 | { |
| 178 | Id: 123, |
| 179 | Key: "foo", |
nothing calls this directly
no test coverage detected