Unverified Commit e943ae55 authored by Bryan Liles's avatar Bryan Liles Committed by GitHub
Browse files

Merge pull request #577 from bryanl/cli-errors

Add additional test coverage to diff
parents c39ca26e 32e65665
......@@ -42,12 +42,11 @@ func main() {
}
log.SetFormatter(logFmt)
log.Error(err.Error())
switch err {
case actions.ErrDiffFound:
os.Exit(10)
default:
log.Error(err.Error())
os.Exit(1)
}
}
......
......@@ -116,7 +116,8 @@ func (d *Diff) Run() error {
return err
}
if buf.String() != "" {
if s := buf.String(); s != "" {
fmt.Fprintln(d.out, s)
return ErrDiffFound
}
......
......@@ -36,6 +36,7 @@ func TestDiff(t *testing.T) {
src2 string
eLocation1 string
eLocation2 string
diffText string
isNewError bool
isRunError bool
}{
......@@ -52,6 +53,15 @@ func TestDiff(t *testing.T) {
eLocation1: "local:default",
eLocation2: "remote:default",
},
{
name: "diff detected",
src1: "local:default",
src2: "remote:default",
eLocation1: "local:default",
eLocation2: "remote:default",
diffText: "+foo\n-bar\nbaz\n",
isRunError: true,
},
}
for _, tc := range cases {
......@@ -80,13 +90,14 @@ func TestDiff(t *testing.T) {
assert.Equal(t, tc.eLocation1, l1.String(), "location1")
assert.Equal(t, tc.eLocation2, l2.String(), "location2")
r := strings.NewReader("")
r := strings.NewReader(tc.diffText)
return r, nil
}
err = d.Run()
if tc.isRunError {
require.Error(t, err)
assert.Error(t, err)
assert.NotEmpty(t, buf.String())
return
}
......
......@@ -52,6 +52,7 @@ application configuration to remote clusters.
----
`,
SilenceErrors: true,
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
goflag.CommandLine.Parse([]string{})
flags := cmd.Flags()
......
......@@ -41,7 +41,7 @@ type Differ struct {
// DefaultDiff runs diff with default options.
func DefaultDiff(a app.App, config *client.Config, l1 *Location, l2 *Location) (io.Reader, error) {
differ := New(a, config)
return differ.Diff(l1, l2)
return differ.Diff(l2, l1)
}
// New creates an instance of Differ.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment