github.com/fern4lvarez/piladb@v0.2.0-alpha.20180407/pkg/version/version_test.go (about) 1 package version 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/mitchellh/go-homedir" 8 ) 9 10 func TestVersion(t *testing.T) { 11 v := "1.0" 12 expectedVersion := "1.0" 13 if version := Version(v); version != expectedVersion { 14 t.Errorf("version is %s, expected %v", version, expectedVersion) 15 } 16 17 v = "" 18 if version := Version(v); len(version) != 40 { 19 t.Errorf("version is unexpected: %s", version) 20 } 21 } 22 23 func TestCommitHash(t *testing.T) { 24 if c := CommitHash(); len(c) != 40 { 25 t.Errorf("commit hash version unexpected: %s", c) 26 } 27 } 28 29 func TestCommitHash_Undefined(t *testing.T) { 30 // normally $HOME is not version controlled 31 home, err := homedir.Dir() 32 if err != nil { 33 t.Fatal("could not get home dir") 34 } 35 36 os.Chdir(home) 37 if h := CommitHash(); h != "undefined" { 38 t.Errorf("CommitHash is %s, expected %s", h, "undefined") 39 } 40 41 }