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

Function TestSubmitWithEmptyFile

cmd/submit_test.go:345–384  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

343}
344
345func TestSubmitWithEmptyFile(t *testing.T) {
346 co := newCapturedOutput()
347 co.override()
348 defer co.reset()
349
350 // The fake endpoint will populate this when it receives the call from the command.
351 submittedFiles := map[string]string{}
352 ts := fakeSubmitServer(t, submittedFiles)
353 defer ts.Close()
354
355 tmpDir, err := os.MkdirTemp("", "empty-file")
356 defer os.RemoveAll(tmpDir)
357 assert.NoError(t, err)
358
359 dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
360 os.MkdirAll(dir, os.FileMode(0755))
361
362 writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
363
364 v := viper.New()
365 v.Set("token", "abc123")
366 v.Set("workspace", tmpDir)
367 v.Set("apibaseurl", ts.URL)
368
369 cfg := config.Config{
370 Persister: config.InMemoryPersister{},
371 UserViperConfig: v,
372 }
373
374 file1 := filepath.Join(dir, "file-1.txt")
375 err = os.WriteFile(file1, []byte(""), os.FileMode(0755))
376 file2 := filepath.Join(dir, "file-2.txt")
377 err = os.WriteFile(file2, []byte("This is file 2."), os.FileMode(0755))
378
379 err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file1, file2})
380 assert.NoError(t, err)
381
382 assert.Equal(t, 1, len(submittedFiles))
383 assert.Equal(t, "This is file 2.", submittedFiles["file-2.txt"])
384}
385
386func TestSubmitWithEnormousFile(t *testing.T) {
387 co := newCapturedOutput()

Callers

nothing calls this directly

Calls 6

newCapturedOutputFunction · 0.85
fakeSubmitServerFunction · 0.85
writeFakeMetadataFunction · 0.85
runSubmitFunction · 0.85
overrideMethod · 0.80
resetMethod · 0.80

Tested by

no test coverage detected