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

Function TestSubmitWithEnormousFile

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

Source from the content-addressed store, hash-verified

384}
385
386func TestSubmitWithEnormousFile(t *testing.T) {
387 co := newCapturedOutput()
388 co.override()
389 defer co.reset()
390
391 // The fake endpoint will populate this when it receives the call from the command.
392 submittedFiles := map[string]string{}
393 ts := fakeSubmitServer(t, submittedFiles)
394 defer ts.Close()
395
396 tmpDir, err := os.MkdirTemp("", "enormous-file")
397 defer os.RemoveAll(tmpDir)
398 assert.NoError(t, err)
399
400 dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
401 os.MkdirAll(dir, os.FileMode(0755))
402
403 writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")
404
405 v := viper.New()
406 v.Set("token", "abc123")
407 v.Set("workspace", tmpDir)
408 v.Set("apibaseurl", ts.URL)
409
410 cfg := config.Config{
411 Persister: config.InMemoryPersister{},
412 UserViperConfig: v,
413 }
414
415 file := filepath.Join(dir, "file.txt")
416 err = os.WriteFile(file, make([]byte, 65535), os.FileMode(0755))
417 if err != nil {
418 t.Fatal(err)
419 }
420
421 err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file})
422
423 if assert.Error(t, err) {
424 assert.Regexp(t, "Please reduce the size of the file and try again.", err.Error())
425 }
426}
427
428func TestSubmitOnlyEmptyFile(t *testing.T) {
429 co := newCapturedOutput()

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected