Skip to content

Commit

Permalink
Merge pull request exercism#771 from jdsutherland/migration-verbose-test
Browse files Browse the repository at this point in the history
Add test for migration output
  • Loading branch information
Katrina Owen authored Nov 28, 2018
2 parents 27178cd + 1aec7ab commit 70022ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
return err
}
if verbose, _ := flags.GetBool("verbose"); verbose {
fmt.Fprintf(os.Stderr, migrationStatus.String())
fmt.Fprintf(Err, migrationStatus.String())
}
metadata, err := workspace.NewExerciseMetadata(exerciseDir)
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions cmd/submit_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -187,15 +188,12 @@ func TestSubmitFiles(t *testing.T) {
}

func TestLegacyMetadataMigration(t *testing.T) {
oldOut := Out
oldErr := Err
Out = ioutil.Discard
Err = ioutil.Discard
defer func() {
Out = oldOut
Err = oldErr
}()
// The fake endpoint will populate this when it receives the call from the command.
Err = &bytes.Buffer{}

submittedFiles := map[string]string{}
ts := fakeSubmitServer(t, submittedFiles)
defer ts.Close()
Expand Down Expand Up @@ -239,14 +237,18 @@ func TestLegacyMetadataMigration(t *testing.T) {
ok, _ = exercise.HasMetadata()
assert.False(t, ok)

err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file})
flags := pflag.NewFlagSet("fake", pflag.PanicOnError)
flags.Bool("verbose", true, "")

err = runSubmit(cfg, flags, []string{file})
assert.NoError(t, err)
assert.Equal(t, "This is a file.", submittedFiles["file.txt"])

ok, _ = exercise.HasLegacyMetadata()
assert.False(t, ok)
ok, _ = exercise.HasMetadata()
assert.True(t, ok)
assert.Regexp(t, "Migrated metadata", Err)
}

func TestSubmitWithEmptyFile(t *testing.T) {
Expand Down

0 comments on commit 70022ab

Please sign in to comment.