Skip to content

Commit

Permalink
Add missing test when metadata not requester (exercism#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdsutherland authored and nywilken committed Dec 15, 2018
1 parent 0500cf5 commit c39243d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
}

if !metadata.IsRequester {
// TODO: add test
msg := `
The solution you are submitting is not connected to your account.
Expand Down
43 changes: 43 additions & 0 deletions cmd/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,49 @@ func TestSubmitRelativePath(t *testing.T) {
assert.Equal(t, "This is a file.", submittedFiles["file.txt"])
}

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

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

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

metadata := &workspace.ExerciseMetadata{
ID: "bogus-solution-uuid",
Track: "bogus-track",
Exercise: "bogus-exercise",
URL: "http://example.com/bogus-url",
IsRequester: false,
}
err = metadata.Write(dir)
assert.NoError(t, err)

file1 := filepath.Join(dir, "file-1.txt")
err = ioutil.WriteFile(file1, []byte("This is file 1."), os.FileMode(0755))
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{},
Dir: tmpDir,
UserViperConfig: v,
}

err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file1})
if assert.Error(t, err) {
assert.Regexp(t, "not connected to your account", err.Error())
}
}

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

0 comments on commit c39243d

Please sign in to comment.