Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
"path/filepath"

Expand Down Expand Up @@ -268,7 +267,7 @@ func (s *submitCmdContext) submit(metadata *workspace.ExerciseMetadata, docs []w
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusBadRequest {
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return decodedAPIError(resp)
}

Expand Down
38 changes: 38 additions & 0 deletions cmd/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,44 @@ func TestSubmitServerErr(t *testing.T) {
assert.Regexp(t, "test error", err.Error())
}

func TestHandleErrorResponse(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for adding this test!

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
})

ts := httptest.NewServer(handler)
defer ts.Close()

tmpDir, err := ioutil.TempDir("", "submit-nonsuccess")
defer os.RemoveAll(tmpDir)
assert.NoError(t, err)

v := viper.New()
v.Set("token", "abc123")
v.Set("workspace", tmpDir)
v.Set("apibaseurl", ts.URL)

cfg := config.Config{
Persister: config.InMemoryPersister{},
UserViperConfig: v,
DefaultBaseURL: "http://example.com",
}

dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
os.MkdirAll(filepath.Join(dir, "subdir"), os.FileMode(0755))
writeFakeMetadata(t, dir, "bogus-track", "bogus-exercise")

err = ioutil.WriteFile(filepath.Join(dir, "file-1.txt"), []byte("This is file 1"), os.FileMode(0755))
assert.NoError(t, err)

files := []string{
filepath.Join(dir, "file-1.txt"),
}

err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), files)
assert.Error(t, err)
}

func TestSubmissionNotConnectedToRequesterAccount(t *testing.T) {
submittedFiles := map[string]string{}
ts := fakeSubmitServer(t, submittedFiles)
Expand Down