Skip to content

Commit

Permalink
resolved some test issues stemming from inconsistent mock behavior
Browse files Browse the repository at this point in the history
Signed-off-by: John Murphy <johnmurphy@salesforce.com>
  • Loading branch information
John Murphy committed May 29, 2019
1 parent d640e6d commit a078ad8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion commands/inspect_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func InspectBuilder(logger logging.Logger, cfg *config.Config, client PackClient
func inspectBuilderOutput(logger logging.Logger, client PackClient, imageName string, local bool) {
info, err := client.InspectBuilder(imageName, local)
if err != nil {
logger.Error(err.Error())
logger.Info("")
logger.Error( err.Error())
return
}

Expand Down
6 changes: 4 additions & 2 deletions commands/inspect_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ func testInspectBuilderCommand(t *testing.T, when spec.G, it spec.S) {

h.AssertContains(t, outBuf.String(), `Remote
------
some remote error
ERROR: some remote error
Local
-----
some local error
ERROR: some local error
`)
})
})
Expand Down
4 changes: 2 additions & 2 deletions commands/set_default_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func testSetDefaultBuilderCommand(t *testing.T, when spec.G, it spec.S) {
command.SetArgs([]string{imageName})

h.AssertNotNil(t, command.Execute())
h.AssertContains(t, outBuf.String(), "failed to inspect image nonbuilder/image")
h.AssertContains(t, outBuf.String(), "ERROR: failed to inspect image nonbuilder/image")
})
})

Expand All @@ -129,7 +129,7 @@ func testSetDefaultBuilderCommand(t *testing.T, when spec.G, it spec.S) {
command.SetArgs([]string{imageName})

h.AssertNotNil(t, command.Execute())
h.AssertContains(t, outBuf.String(), "builder 'nonexisting/image' not found")
h.AssertContains(t, outBuf.String(), "ERROR: builder 'nonexisting/image' not found")
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion commands/suggest_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func SuggestStacks(logger logging.Logger) *cobra.Command {
Use: "suggest-stacks",
Short: "Display list of recommended stacks",
Args: cobra.NoArgs,
RunE: logError(nil, func(cmd *cobra.Command, args []string) error {
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
suggestStacks(logger)
return nil
}),
Expand Down
4 changes: 4 additions & 0 deletions internal/mocks/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func NewMockLogger(w io.Writer) *mockLog {
}

func (ml *mockLog) HandleLog(e *log.Entry) error {
if e.Level == log.ErrorLevel {
_, _ = fmt.Fprintf(ml.w, "ERROR: %s\n", e.Message)
return nil
}
_, _ = fmt.Fprintln(ml.w, e.Message)
return nil
}
Expand Down

0 comments on commit a078ad8

Please sign in to comment.