Skip to content

Commit 1aec7ab

Browse files
committed
Add test for migration output
Previously printing referenced `os.Stderr` instead of `Err` as done elsewhere Having fixed this, it seems fit to verify migration printing output
1 parent 27178cd commit 1aec7ab

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

cmd/submit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func runSubmit(cfg config.Config, flags *pflag.FlagSet, args []string) error {
134134
return err
135135
}
136136
if verbose, _ := flags.GetBool("verbose"); verbose {
137-
fmt.Fprintf(os.Stderr, migrationStatus.String())
137+
fmt.Fprintf(Err, migrationStatus.String())
138138
}
139139
metadata, err := workspace.NewExerciseMetadata(exerciseDir)
140140
if err != nil {

cmd/submit_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"io/ioutil"
67
"net/http"
@@ -187,15 +188,12 @@ func TestSubmitFiles(t *testing.T) {
187188
}
188189

189190
func TestLegacyMetadataMigration(t *testing.T) {
190-
oldOut := Out
191191
oldErr := Err
192-
Out = ioutil.Discard
193-
Err = ioutil.Discard
194192
defer func() {
195-
Out = oldOut
196193
Err = oldErr
197194
}()
198-
// The fake endpoint will populate this when it receives the call from the command.
195+
Err = &bytes.Buffer{}
196+
199197
submittedFiles := map[string]string{}
200198
ts := fakeSubmitServer(t, submittedFiles)
201199
defer ts.Close()
@@ -239,14 +237,18 @@ func TestLegacyMetadataMigration(t *testing.T) {
239237
ok, _ = exercise.HasMetadata()
240238
assert.False(t, ok)
241239

242-
err = runSubmit(cfg, pflag.NewFlagSet("fake", pflag.PanicOnError), []string{file})
240+
flags := pflag.NewFlagSet("fake", pflag.PanicOnError)
241+
flags.Bool("verbose", true, "")
242+
243+
err = runSubmit(cfg, flags, []string{file})
243244
assert.NoError(t, err)
244245
assert.Equal(t, "This is a file.", submittedFiles["file.txt"])
245246

246247
ok, _ = exercise.HasLegacyMetadata()
247248
assert.False(t, ok)
248249
ok, _ = exercise.HasMetadata()
249250
assert.True(t, ok)
251+
assert.Regexp(t, "Migrated metadata", Err)
250252
}
251253

252254
func TestSubmitWithEmptyFile(t *testing.T) {

0 commit comments

Comments
 (0)