Skip to content

Commit

Permalink
Drive out errors
Browse files Browse the repository at this point in the history
[#151229598]

Signed-off-by: Slawek Ligus <[email protected]>
  • Loading branch information
christianang authored and Slawek Ligus committed Sep 22, 2017
1 parent 4d46c2f commit 1cbea4a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func NewCompare(stdout, stderr io.Writer) Compare {
func (c Compare) Execute(args []string) error {
v1, err := semverMake(args[0])
if err != nil {
panic(err)
return err
}

v2, err := semverMake(args[1])
if err != nil {
panic(err)
return err
}

c.stdout.Write([]byte(fmt.Sprintf("%d\n", semverCompare(v1, v2))))
Expand Down
19 changes: 19 additions & 0 deletions cmd/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd_test

import (
"bytes"
"errors"

"github.com/blang/semver"
"github.com/christianang/semver-cli/cmd"
Expand Down Expand Up @@ -53,5 +54,23 @@ var _ = Describe("Compare", func() {
Expect(fakeSemver.MakeArgsForCall(1)).To(Equal("1.12.5"))
Expect(stdout.String()).To(Equal("9999\n"))
})

Context("when an error occurs", func() {
Context("when the first semver is invalid", func() {
It("returns an error", func() {
fakeSemver.MakeReturnsOnCall(0, semver.Version{}, errors.New("failed to make"))
err := command.Execute([]string{"1.x.x.x", "1.12.5"})
Expect(err).To(MatchError("failed to make"))
})
})

Context("when the first semver is invalid", func() {
It("returns an error", func() {
fakeSemver.MakeReturnsOnCall(1, semver.Version{}, errors.New("failed to make"))
err := command.Execute([]string{"1.x.x.x", "1.12.5"})
Expect(err).To(MatchError("failed to make"))
})
})
})
})
})

0 comments on commit 1cbea4a

Please sign in to comment.