diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/utils.go | 2 | ||||
-rw-r--r-- | model/version.go | 56 | ||||
-rw-r--r-- | model/version_test.go | 36 |
3 files changed, 54 insertions, 40 deletions
diff --git a/model/utils.go b/model/utils.go index ee94cafc3..e19cceba5 100644 --- a/model/utils.go +++ b/model/utils.go @@ -230,7 +230,7 @@ func IsValidAlphaNum(s string, allowUnderscores bool) bool { func Etag(parts ...interface{}) string { - etag := GetFullVersion() + etag := CurrentVersion for _, part := range parts { etag += fmt.Sprintf(".%v", part) diff --git a/model/version.go b/model/version.go index e3e6e14b9..8b5258ec1 100644 --- a/model/version.go +++ b/model/version.go @@ -4,23 +4,26 @@ package model import ( - "fmt" "strconv" "strings" ) -const ( - VERSION_MAJOR = 0 - VERSION_MINOR = 8 - VERSION_PATCH = 0 - BUILD_NUMBER = "_BUILD_NUMBER_" - BUILD_DATE = "_BUILD_DATE_" -) - -func GetFullVersion() string { - return fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) +// This is a list of all the current viersions including any patches. +// It should be maitained in chronological order with most current +// release at the front of the list. +var versions = []string{ + "0.8.0", + "0.7.1", + "0.7.0", + "0.6.0", + "0.5.0", } +var CurrentVersion string = versions[0] +var BuildNumber = "developer" +var BuildDate = "unknown" +var BuildHash = "unknown" + func SplitVersion(version string) (int64, int64, int64) { parts := strings.Split(version, ".") @@ -43,32 +46,41 @@ func SplitVersion(version string) (int64, int64, int64) { return major, minor, patch } -func GetPreviousVersion(version string) (int64, int64) { - major, minor, _ := SplitVersion(version) +func GetPreviousVersion(currentVersion string) (int64, int64) { + currentIndex := -1 + currentMajor, currentMinor, _ := SplitVersion(currentVersion) - if minor == 0 { - major = major - 1 - minor = 9 - } else { - minor = minor - 1 + for index, version := range versions { + major, minor, _ := SplitVersion(version) + + if currentMajor == major && currentMinor == minor { + currentIndex = index + } + + if currentIndex >= 0 { + if currentMajor != major || currentMinor != minor { + return major, minor + } + } } - return major, minor + return 0, 0 } func IsCurrentVersion(versionToCheck string) bool { + currentMajor, currentMinor, _ := SplitVersion(CurrentVersion) toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck) - if toCheckMajor == VERSION_MAJOR && toCheckMinor == VERSION_MINOR { + if toCheckMajor == currentMajor && toCheckMinor == currentMinor { return true } else { return false } } -func IsLastVersion(versionToCheck string) bool { +func IsPreviousVersion(versionToCheck string) bool { toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck) - prevMajor, prevMinor := GetPreviousVersion(GetFullVersion()) + prevMajor, prevMinor := GetPreviousVersion(CurrentVersion) if toCheckMajor == prevMajor && toCheckMinor == prevMinor { return true diff --git a/model/version_test.go b/model/version_test.go index fb52d96a5..da40006be 100644 --- a/model/version_test.go +++ b/model/version_test.go @@ -8,9 +8,7 @@ import ( "testing" ) -func TestVersion(t *testing.T) { - GetFullVersion() - +func TestSplitVersion(t *testing.T) { major1, minor1, patch1 := SplitVersion("junk") if major1 != 0 || minor1 != 0 || patch1 != 0 { t.Fatal() @@ -35,38 +33,42 @@ func TestVersion(t *testing.T) { if major5 != 1 || minor5 != 2 || patch5 != 3 { t.Fatal() } +} - if IsLastVersion(GetFullVersion()) { - t.Fatal() +func TestGetPreviousVersion(t *testing.T) { + if major, minor := GetPreviousVersion("0.8.0"); major != 0 || minor != 7 { + t.Fatal(major, minor) } - if !IsLastVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR-1, VERSION_PATCH)) { - t.Fatal() + if major, minor := GetPreviousVersion("0.7.0"); major != 0 || minor != 6 { + t.Fatal(major, minor) } - // pacth should not affect current version check - if !IsLastVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR-1, VERSION_PATCH+1)) { - t.Fatal() + if major, minor := GetPreviousVersion("0.7.1"); major != 0 || minor != 6 { + t.Fatal(major, minor) } - if IsLastVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR+1, VERSION_PATCH)) { - t.Fatal() + if major, minor := GetPreviousVersion("0.7111.1"); major != 0 || minor != 0 { + t.Fatal(major, minor) } +} + +func TestIsCurrentVersion(t *testing.T) { + major, minor, patch := SplitVersion(CurrentVersion) - if !IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)) { + if !IsCurrentVersion(CurrentVersion) { t.Fatal() } - // pacth should not affect current version check - if !IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH+1)) { + if !IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major, minor, patch+100)) { t.Fatal() } - if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR, VERSION_MINOR+1, VERSION_PATCH)) { + if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major, minor+1, patch)) { t.Fatal() } - if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", VERSION_MAJOR+1, VERSION_MINOR, VERSION_PATCH)) { + if IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major+1, minor, patch)) { t.Fatal() } } |