@@ -295,6 +295,52 @@ func TestSubmitWithEmptyFile(t *testing.T) {
295295 assert .Equal (t , "This is file 2." , submittedFiles ["file-2.txt" ])
296296}
297297
298+ func TestSubmitWithEnormousFile (t * testing.T ) {
299+ oldOut := Out
300+ oldErr := Err
301+ Out = ioutil .Discard
302+ Err = ioutil .Discard
303+ defer func () {
304+ Out = oldOut
305+ Err = oldErr
306+ }()
307+
308+ // The fake endpoint will populate this when it receives the call from the command.
309+ submittedFiles := map [string ]string {}
310+ ts := fakeSubmitServer (t , submittedFiles )
311+ defer ts .Close ()
312+
313+ tmpDir , err := ioutil .TempDir ("" , "enormous-file" )
314+ defer os .RemoveAll (tmpDir )
315+ assert .NoError (t , err )
316+
317+ dir := filepath .Join (tmpDir , "bogus-track" , "bogus-exercise" )
318+ os .MkdirAll (dir , os .FileMode (0755 ))
319+
320+ writeFakeSolution (t , dir , "bogus-track" , "bogus-exercise" )
321+
322+ v := viper .New ()
323+ v .Set ("token" , "abc123" )
324+ v .Set ("workspace" , tmpDir )
325+ v .Set ("apibaseurl" , ts .URL )
326+
327+ cfg := config.Config {
328+ Persister : config.InMemoryPersister {},
329+ UserViperConfig : v ,
330+ }
331+
332+ file := filepath .Join (dir , "file.txt" )
333+ err = ioutil .WriteFile (file , make ([]byte , 65535 ), os .FileMode (0755 ))
334+ if err != nil {
335+ t .Fatal (err )
336+ }
337+
338+ err = runSubmit (cfg , pflag .NewFlagSet ("fake" , pflag .PanicOnError ), []string {file })
339+
340+ assert .Error (t , err )
341+ assert .Regexp (t , "Please reduce the size of the file and try again." , err .Error ())
342+ }
343+
298344func TestSubmitFilesForTeamExercise (t * testing.T ) {
299345 oldOut := Out
300346 oldErr := Err
0 commit comments