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

Function TestDownloadToExistingDirectory

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

Source from the content-addressed store, hash-verified

204}
205
206func TestDownloadToExistingDirectory(t *testing.T) {
207 co := newCapturedOutput()
208 co.override()
209 defer co.reset()
210
211 testCases := []struct {
212 exerciseDir string
213 flags map[string]string
214 }{
215 {
216 exerciseDir: filepath.Join("bogus-track", "bogus-exercise"),
217 flags: map[string]string{"exercise": "bogus-exercise", "track": "bogus-track"},
218 },
219 }
220
221 for _, tc := range testCases {
222 tmpDir, err := os.MkdirTemp("", "download-cmd")
223 defer os.RemoveAll(tmpDir)
224 assert.NoError(t, err)
225
226 err = os.MkdirAll(filepath.Join(tmpDir, tc.exerciseDir), os.FileMode(0755))
227 assert.NoError(t, err)
228
229 ts := fakeDownloadServer("true")
230 defer ts.Close()
231
232 v := viper.New()
233 v.Set("workspace", tmpDir)
234 v.Set("apibaseurl", ts.URL)
235 v.Set("token", "abc123")
236
237 cfg := config.Config{
238 UserViperConfig: v,
239 }
240 flags := pflag.NewFlagSet("fake", pflag.PanicOnError)
241 setupDownloadFlags(flags)
242 for name, value := range tc.flags {
243 flags.Set(name, value)
244 }
245
246 err = runDownload(cfg, flags, []string{})
247
248 if assert.Error(t, err) {
249 assert.Regexp(t, "directory '.+' already exists", err.Error())
250 }
251 }
252}
253
254func TestDownloadToExistingDirectoryWithForce(t *testing.T) {
255 co := newCapturedOutput()

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected