Skip to content

Commit

Permalink
Fix apache#1333: reduce test verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Mar 19, 2020
1 parent 19b92f6 commit 4699798
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
13 changes: 10 additions & 3 deletions e2e/offline_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
package e2e

import (
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -32,10 +33,16 @@ func TestKamelVersionWorksOffline(t *testing.T) {
}

func TestKamelHelpTraitWorksOffline(t *testing.T) {
assert.Nil(t, kamel("help", "trait", "--all", "--config", "non-existent-kubeconfig-file").Execute())
traitCmd := kamel("help", "trait", "--all", "--config", "non-existent-kubeconfig-file")
traitCmd.SetOut(ioutil.Discard)
assert.Nil(t, traitCmd.Execute())
}

func TestKamelCompletionWorksOffline(t *testing.T) {
assert.Nil(t, kamel("completion", "bash", "--config", "non-existent-kubeconfig-file").Execute())
assert.Nil(t, kamel("completion", "zsh", "--config", "non-existent-kubeconfig-file").Execute())
bashCmd := kamel("completion", "bash", "--config", "non-existent-kubeconfig-file")
bashCmd.SetOut(ioutil.Discard)
zshCmd := kamel("completion", "zsh", "--config", "non-existent-kubeconfig-file")
zshCmd.SetOut(ioutil.Discard)
assert.Nil(t, bashCmd.Execute())
assert.Nil(t, zshCmd.Execute())
}
12 changes: 6 additions & 6 deletions pkg/cmd/trait_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func newTraitHelpCmd(rootCmdOptions *RootCmdOptions) (*cobra.Command, *traitHelp
Short: "Trait help information",
Long: `Displays help information for traits in a specified output format.`,
PreRunE: decode(&options),
RunE: func(_ *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
if err := options.validate(args); err != nil {
return err
}
return options.run(args)
return options.run(cmd, args)
},
Annotations: map[string]string{
offlineCommandLabel: "true",
Expand Down Expand Up @@ -92,7 +92,7 @@ func (command *traitHelpCommandOptions) validate(args []string) error {
return nil
}

func (command *traitHelpCommandOptions) run(args []string) error {
func (command *traitHelpCommandOptions) run(cmd *cobra.Command, args []string) error {
var traitDescriptions []*traitDescription
var catalog = trait.NewCatalog(command.Context, nil)

Expand Down Expand Up @@ -127,15 +127,15 @@ func (command *traitHelpCommandOptions) run(args []string) error {
if err != nil {
return err
}
fmt.Println(string(res))
fmt.Fprintln(cmd.OutOrStdout(), string(res))
case "YAML":
res, err := yaml.Marshal(traitDescriptions)
if err != nil {
return err
}
fmt.Println(string(res))
fmt.Fprintln(cmd.OutOrStdout(), string(res))
default:
fmt.Println(outputTraits(traitDescriptions))
fmt.Fprintln(cmd.OutOrStdout(), outputTraits(traitDescriptions))
}

return nil
Expand Down

0 comments on commit 4699798

Please sign in to comment.