Skip to content

Commit

Permalink
fix: Correcting Case Sensitivity (#29)
Browse files Browse the repository at this point in the history
Additionally exposing error to CLI output and fixing tests
  • Loading branch information
stjohnjohnson authored and d2lam committed Sep 27, 2018
1 parent c72bcf3 commit eaeb349
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
12 changes: 6 additions & 6 deletions gitversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Bump(prefix string, field string) error {
if len(m) == 0 {
field = Patch
} else {
field = m[MatchField]
field = strings.ToLower(m[MatchField])
}
}
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func main() {
Usage: "bump the prerelease version",
Action: func(c *cli.Context) error {
if err := Bump(prefix, PreRelease); err != nil {
fmt.Fprint(os.Stderr, "Error: ")
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return err
}
return nil
Expand All @@ -188,7 +188,7 @@ func main() {
Usage: "bump the patch version",
Action: func(c *cli.Context) error {
if err := Bump(prefix, Patch); err != nil {
fmt.Fprint(os.Stderr, "Error: ")
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return err
}
return nil
Expand All @@ -199,7 +199,7 @@ func main() {
Usage: "bump the minor version",
Action: func(c *cli.Context) error {
if err := Bump(prefix, Minor); err != nil {
fmt.Fprint(os.Stderr, "Error: ")
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return err
}
return nil
Expand All @@ -210,7 +210,7 @@ func main() {
Usage: "bump the major version",
Action: func(c *cli.Context) error {
if err := Bump(prefix, Major); err != nil {
fmt.Fprint(os.Stderr, "Error: ")
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return err
}
return nil
Expand All @@ -221,7 +221,7 @@ func main() {
Usage: "bump the version specified in the last commit",
Action: func(c *cli.Context) error {
if err := Bump(prefix, Auto); err != nil {
fmt.Fprint(os.Stderr, "Error: ")
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return err
}
return nil
Expand Down
49 changes: 38 additions & 11 deletions gitversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ func TestBumpAutoTagged(t *testing.T) {
}
defer func() { gitTagged = git.Tagged }()

Bump("", Auto)
err := Bump("", Auto)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestBumpAutoMatch(t *testing.T) {
Expand Down Expand Up @@ -125,7 +128,10 @@ func TestBumpAutoMatch(t *testing.T) {
}
defer func() { gitMessage = git.LastCommitMessage }()

Bump("", Auto)
err := Bump("", Auto)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestBumpAutoMatchAlternate(t *testing.T) {
Expand Down Expand Up @@ -153,7 +159,10 @@ func TestBumpAutoMatchAlternate(t *testing.T) {
}
defer func() { gitMessage = git.LastCommitMessage }()

Bump("", Auto)
err := Bump("", Auto)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestBumpAutoMatchFallback(t *testing.T) {
Expand Down Expand Up @@ -181,7 +190,10 @@ func TestBumpAutoMatchFallback(t *testing.T) {
}
defer func() { gitMessage = git.LastCommitMessage }()

Bump("", Auto)
err := Bump("", Auto)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestBumpPreRelease(t *testing.T) {
Expand All @@ -204,7 +216,10 @@ func TestBumpPreRelease(t *testing.T) {
}
defer func() { gitTags = git.Tags }()

Bump("", PreRelease)
err := Bump("", PreRelease)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestBumpPatch(t *testing.T) {
Expand All @@ -222,7 +237,10 @@ func TestBumpPatch(t *testing.T) {
}
defer func() { gitTags = git.Tags }()

Bump("", Patch)
err := Bump("", Patch)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestBumpMinor(t *testing.T) {
Expand All @@ -240,7 +258,10 @@ func TestBumpMinor(t *testing.T) {
}
defer func() { gitTags = git.Tags }()

Bump("", Minor)
err := Bump("", Minor)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestBumpMajor(t *testing.T) {
Expand All @@ -258,7 +279,10 @@ func TestBumpMajor(t *testing.T) {
}
defer func() { gitTags = git.Tags }()

Bump("", Major)
err := Bump("", Major)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestBumpWithNoVersions(t *testing.T) {
Expand All @@ -276,7 +300,10 @@ func TestBumpWithNoVersions(t *testing.T) {
}
defer func() { gitTags = git.Tags }()

Bump("", Patch)
err := Bump("", Patch)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestBumpWithBadField(t *testing.T) {
Expand All @@ -295,8 +322,8 @@ func TestBumpWithBadField(t *testing.T) {
defer func() { gitTags = git.Tags }()

err := Bump("", "foobar")
if err == nil {
t.Error("expected error from Bump()")
if err.Error() != "unknown field type" {
t.Errorf("Unexpected error: %v", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion screwdriver.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
shared:
image: golang
image: golang:1.10
environment:
GOPATH: /sd/workspace

Expand Down

0 comments on commit eaeb349

Please # to comment.