Skip to content

Commit

Permalink
Adding tests and using new gopath domain
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hein <me@chrishein.com>
  • Loading branch information
christopherhein committed Jun 21, 2019
1 parent fee8dd1 commit 812a3b5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module go.hein.dev/go-version

go 1.12
13 changes: 11 additions & 2 deletions readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package main
import (
"fmt"
goVersion "github.com/christopherhein/go-version"
goversion "go.hein.dev/go-version"
"github.com/spf13/cobra"
)
Expand All @@ -30,7 +30,7 @@ var (
Long: ``,
Run: func(_ *cobra.Command, _ []string) {
var response string
versionOutput := goVersion.New(version, commit, date)
versionOutput := goversion.New(version, commit, date)
if shortened {
response = versionOutput.ToShortened()
Expand Down Expand Up @@ -75,6 +75,15 @@ Commit: <SOMEHASH>
Date: <SOMEDATE>
----

== Testing

To run the test suite all you need to do is run.

[source,shell]
----
go test -v ./...
----

== Contributing

If you want to contribute check out
Expand Down
27 changes: 27 additions & 0 deletions version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package version

import "testing"

func TestToJSON(t *testing.T) {
v := New("dev", "fee8dd1f7c24da23508e26347694be0acce5631b", "Fri Jun 21 10:50:15 PDT 2019")
json := v.ToJSON()

expected := "{\"Version\":\"dev\",\"Commit\":\"fee8dd1f7c24da23508e26347694be0acce5631b\",\"Date\":\"Fri Jun 21 10:50:15 PDT 2019\"}\n"
if json != expected {
t.Errorf("Expected json %s to equal %s", json, expected)
}
}

func TestToShortened(t *testing.T) {
v := New("dev", "fee8dd1f7c24da23508e26347694be0acce5631b", "Fri Jun 21 10:50:15 PDT 2019")
short := v.ToShortened()

expected := `Version: dev
Commit: fee8dd1f7c24da23508e26347694be0acce5631b
Date: Fri Jun 21 10:50:15 PDT 2019
`

if short != expected {
t.Errorf("Expected shortened %s to equal %s", short, expected)
}
}

0 comments on commit 812a3b5

Please sign in to comment.