Skip to content

Commit 881a90b

Browse files
committed
Address nywilken's review
* rename test * test artifact cleanup * during test, check expected migration path DNE before migration * when checking solution files, check for a modern solution before legacy
1 parent 1281e63 commit 881a90b

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

cmd/submit_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func TestSubmitOnlyEmptyFile(t *testing.T) {
261261
assert.Regexp(t, "No files found", err.Error())
262262
}
263263

264-
func TestSubmitExerciseWithLegacySolutionMetadataFileAndGetsMigrated(t *testing.T) {
264+
func TestLegacySolutionMetadataMigration(t *testing.T) {
265265
oldOut := Out
266266
oldErr := Err
267267
Out = ioutil.Discard
@@ -276,6 +276,7 @@ func TestSubmitExerciseWithLegacySolutionMetadataFileAndGetsMigrated(t *testing.
276276
defer ts.Close()
277277

278278
tmpDir, err := ioutil.TempDir("", "legacy-metadata-file")
279+
defer os.RemoveAll(tmpDir)
279280
assert.NoError(t, err)
280281

281282
dir := filepath.Join(tmpDir, "bogus-track", "bogus-exercise")
@@ -296,6 +297,8 @@ func TestSubmitExerciseWithLegacySolutionMetadataFileAndGetsMigrated(t *testing.
296297
UserViperConfig: v,
297298
}
298299
expectedSolutionPathAfterMigration := filepath.Join(dir, workspace.SolutionMetadataFilepath())
300+
_, err = os.Stat(expectedSolutionPathAfterMigration)
301+
assert.Error(t, err)
299302

300303
err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file})
301304
assert.NoError(t, err)

workspace/solution.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ func (s *Solution) String() string {
6060
}
6161

6262
// Write stores solution metadata to a file.
63-
func (s *Solution) Write(path string) error {
63+
func (s *Solution) Write(dir string) error {
6464
b, err := json.Marshal(s)
6565
if err != nil {
6666
return err
6767
}
68-
if err = createIgnoreSubdir(path); err != nil {
68+
if err = createIgnoreSubdir(dir); err != nil {
6969
return err
7070
}
71-
if err = ioutil.WriteFile(filepath.Join(path, SolutionMetadataFilepath()), b, os.FileMode(0600)); err != nil {
71+
if err = ioutil.WriteFile(filepath.Join(dir, SolutionMetadataFilepath()), b, os.FileMode(0600)); err != nil {
7272
return err
7373
}
74-
s.Dir = path
75-
return err
74+
s.Dir = dir
75+
return nil
7676
}
7777

7878
// PathToParent is the relative path from the workspace to the parent dir.

workspace/workspace.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ func checkSolutionFile(path string) error {
209209
legacySolutionPath := filepath.Join(path, ".solution.json")
210210
solutionPath := filepath.Join(path, SolutionMetadataFilepath())
211211

212-
if _, err := os.Lstat(legacySolutionPath); err == nil {
212+
var err error
213+
if _, err = os.Lstat(solutionPath); err == nil {
214+
return nil
215+
} else if _, err2 := os.Lstat(legacySolutionPath); err2 == nil {
213216
return migrateLegacySolutionFile(legacySolutionPath, solutionPath)
214-
} else if _, err := os.Lstat(solutionPath); err != nil {
215-
return err
216217
}
217-
return nil
218+
return err
218219
}

0 commit comments

Comments
 (0)