-
-
Notifications
You must be signed in to change notification settings - Fork 368
717 submit enormous files #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,14 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| if info.Size() >= int64(65535) { | ||
| msg :=` | ||
|
|
||
| The file you are trying to submit is %d bytes. Please reduce the file to below 65535 bytes and try again. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small suggestion on the messaging
We can use the const here as well for printing and test explicitly for this message. This error will also throw golint error because the error message starts with a capital letter, but that’s okay right now because of how we are printing this errors. We’ll solve that later for submit and download. |
||
|
|
||
| ` | ||
| return fmt.Errorf(msg, info.Size()) | ||
| } | ||
| if info.Size() == 0 { | ||
|
|
||
| msg := ` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,6 +230,48 @@ func TestSubmitWithEmptyFile(t *testing.T) { | |
| assert.Equal(t, "This is file 2.", submittedFiles["file-2.txt"]) | ||
| } | ||
|
|
||
| func TestSubmitWithEnormousFile(t *testing.T) { | ||
| oldOut := Out | ||
| oldErr := Err | ||
| Out = ioutil.Discard | ||
| Err = ioutil.Discard | ||
| defer func() { | ||
| Out = oldOut | ||
| Err = oldErr | ||
| }() | ||
|
|
||
| // The fake endpoint will populate this when it receives the call from the command. | ||
| submittedFiles := map[string]string{} | ||
| ts := fakeSubmitServer(t, submittedFiles) | ||
| defer ts.Close() | ||
|
|
||
| tmpDir, err := ioutil.TempDir("", "enormous-file") | ||
| defer os.RemoveAll(tmpDir) | ||
| assert.NoError(t, err) | ||
|
|
||
| dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise") | ||
| os.MkdirAll(dir, os.FileMode(0755)) | ||
|
|
||
| writeFakeSolution(t, dir, "bogus-track", "bogus-exercise") | ||
|
|
||
| v := viper.New() | ||
| v.Set("token", "abc123") | ||
| v.Set("workspace", tmpDir) | ||
| v.Set("apibaseurl", ts.URL) | ||
|
|
||
| cfg := config.Config{ | ||
| Persister: config.InMemoryPersister{}, | ||
| UserViperConfig: v, | ||
| } | ||
|
|
||
| file := filepath.Join(dir, "file.txt") | ||
| err = ioutil.WriteFile(file, make([]byte, 65535), os.FileMode(0755)) | ||
|
nywilken marked this conversation as resolved.
sfairchild marked this conversation as resolved.
|
||
|
|
||
| err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file}) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let’s assert that we have an error |
||
| assert.Regexp(t, "Please reduce the file to below 65535 bytes and try again.", err.Error()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my suggestion above about the messaging and using a const variable. |
||
| } | ||
|
|
||
| func TestSubmitFilesForTeamExercise(t *testing.T) { | ||
| oldOut := Out | ||
| oldErr := Err | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can turn this into an unxported constant
const maxFileSize int64 = 65535