Skip to content

Commit c39243d

Browse files
jdsutherlandnywilken
authored andcommitted
Add missing test when metadata not requester (#777)
1 parent 0500cf5 commit c39243d

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

cmd/submit.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
156156
}
157157

158158
if !metadata.IsRequester {
159-
// TODO: add test
160159
msg := `
161160
162161
The solution you are submitting is not connected to your account.

cmd/submit_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,49 @@ func TestSubmitRelativePath(t *testing.T) {
548548
assert.Equal(t, "This is a file.", submittedFiles["file.txt"])
549549
}
550550

551+
func TestSubmissionNotConnectedToRequesterAccount(t *testing.T) {
552+
submittedFiles := map[string]string{}
553+
ts := fakeSubmitServer(t, submittedFiles)
554+
defer ts.Close()
555+
556+
tmpDir, err := ioutil.TempDir("", "submit-files")
557+
defer os.RemoveAll(tmpDir)
558+
assert.NoError(t, err)
559+
560+
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
561+
os.MkdirAll(filepath.Join(dir, "subdir"), os.FileMode(0755))
562+
563+
metadata := &workspace.ExerciseMetadata{
564+
ID: "bogus-solution-uuid",
565+
Track: "bogus-track",
566+
Exercise: "bogus-exercise",
567+
URL: "http://example.com/bogus-url",
568+
IsRequester: false,
569+
}
570+
err = metadata.Write(dir)
571+
assert.NoError(t, err)
572+
573+
file1 := filepath.Join(dir, "file-1.txt")
574+
err = ioutil.WriteFile(file1, []byte("This is file 1."), os.FileMode(0755))
575+
assert.NoError(t, err)
576+
577+
v := viper.New()
578+
v.Set("token", "abc123")
579+
v.Set("workspace", tmpDir)
580+
v.Set("apibaseurl", ts.URL)
581+
582+
cfg := config.Config{
583+
Persister: config.InMemoryPersister{},
584+
Dir: tmpDir,
585+
UserViperConfig: v,
586+
}
587+
588+
err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file1})
589+
if assert.Error(t, err) {
590+
assert.Regexp(t, "not connected to your account", err.Error())
591+
}
592+
}
593+
551594
func TestExerciseDirnameMatchesMetadataSlug(t *testing.T) {
552595
submittedFiles := map[string]string{}
553596
ts := fakeSubmitServer(t, submittedFiles)

0 commit comments

Comments
 (0)