Skip to content
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

717 submit enormous files #725

Merged
merged 4 commits into from
Sep 5, 2018

Conversation

sfairchild
Copy link
Contributor

@sfairchild sfairchild commented Aug 29, 2018

Closes #717

Throws an error if file is larger than 65535 bytes

Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfairchild thanks again for your recent contributions 🙏🏽

I left a few suggestions and called out a couple of gotchas to look out for. Please let me know if you have questions.

cmd/submit.go Outdated
@@ -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) {
Copy link
Contributor

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

cmd/submit.go Outdated
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion on the messaging

The submitted file is larger than the max allowed file size of %d bytes. Please reduce the size of the file and try again.

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.

cmd/submit_test.go Show resolved Hide resolved
err = ioutil.WriteFile(file, make([]byte, 65535), os.FileMode(0755))

err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s assert that we have an error assert.EqualError. I’ve seen cases in the past where the error check was skipped, and then resulted in a nil reference error when calling err.Error(). Which cluters the test output making it just a little longer to debug.


err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file})

assert.Regexp(t, "Please reduce the file to below 65535 bytes and try again.", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my suggestion above about the messaging and using a const variable.

@sfairchild
Copy link
Contributor Author

Thank you @nywilken. Go isn't my primary language and I just started learning it. I updated based on your comments and let me know if you have other concerns.

Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfairchild glad to help get this merged in. Thanks for the contribution. I left one more comment pertaining to the name of the constant, but this is solid. I tested locally will files of various sizes and all works as expected.

cmd/submit_test.go Show resolved Hide resolved
cmd/submit.go Outdated
@@ -151,6 +151,15 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
if err != nil {
return err
}
const MaxFileSize int64 = 65535
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Go variable names starting with a capital letter usually denote exported variables (shared across the package). Given the scope in which this constant is defined it can not be exported.

In an attempt to keep things inline with the Code review section for Go https://github.com/golang/go/wiki/CodeReviewComments#mixed-caps this const should be called maxFileSize.

@nywilken nywilken merged commit beef618 into exercism:master Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants