MCPcopy Create free account
hub / github.com/exercism/cli / TestDownloadToExistingDirectoryWithForce

Function TestDownloadToExistingDirectoryWithForce

cmd/download_test.go:254–298  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

252}
253
254func TestDownloadToExistingDirectoryWithForce(t *testing.T) {
255 co := newCapturedOutput()
256 co.override()
257 defer co.reset()
258
259 testCases := []struct {
260 exerciseDir string
261 flags map[string]string
262 }{
263 {
264 exerciseDir: filepath.Join("bogus-track", "bogus-exercise"),
265 flags: map[string]string{"exercise": "bogus-exercise", "track": "bogus-track"},
266 },
267 }
268
269 for _, tc := range testCases {
270 tmpDir, err := os.MkdirTemp("", "download-cmd")
271 defer os.RemoveAll(tmpDir)
272 assert.NoError(t, err)
273
274 err = os.MkdirAll(filepath.Join(tmpDir, tc.exerciseDir), os.FileMode(0755))
275 assert.NoError(t, err)
276
277 ts := fakeDownloadServer("true")
278 defer ts.Close()
279
280 v := viper.New()
281 v.Set("workspace", tmpDir)
282 v.Set("apibaseurl", ts.URL)
283 v.Set("token", "abc123")
284
285 cfg := config.Config{
286 UserViperConfig: v,
287 }
288 flags := pflag.NewFlagSet("fake", pflag.PanicOnError)
289 setupDownloadFlags(flags)
290 for name, value := range tc.flags {
291 flags.Set(name, value)
292 }
293 flags.Set("force", "true")
294
295 err = runDownload(cfg, flags, []string{})
296 assert.NoError(t, err)
297 }
298}
299
300func fakeDownloadServer(requestor string) *httptest.Server {
301 mux := http.NewServeMux()

Callers

nothing calls this directly

Calls 6

newCapturedOutputFunction · 0.85
fakeDownloadServerFunction · 0.85
setupDownloadFlagsFunction · 0.85
runDownloadFunction · 0.85
overrideMethod · 0.80
resetMethod · 0.80

Tested by

no test coverage detected