Merge branch 'master' into add-libcontainer
Conflicts: execdriver/termconsole.go Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
commit
87e010b2e9
2 changed files with 77 additions and 0 deletions
52
version/version.go
Normal file
52
version/version.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Version string
|
||||
|
||||
func (me Version) compareTo(other string) int {
|
||||
var (
|
||||
meTab = strings.Split(string(me), ".")
|
||||
otherTab = strings.Split(other, ".")
|
||||
)
|
||||
for i, s := range meTab {
|
||||
var meInt, otherInt int
|
||||
meInt, _ = strconv.Atoi(s)
|
||||
if len(otherTab) > i {
|
||||
otherInt, _ = strconv.Atoi(otherTab[i])
|
||||
}
|
||||
if meInt > otherInt {
|
||||
return 1
|
||||
}
|
||||
if otherInt > meInt {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
if len(otherTab) > len(meTab) {
|
||||
return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (me Version) LessThan(other string) bool {
|
||||
return me.compareTo(other) == -1
|
||||
}
|
||||
|
||||
func (me Version) LessThanOrEqualTo(other string) bool {
|
||||
return me.compareTo(other) <= 0
|
||||
}
|
||||
|
||||
func (me Version) GreaterThan(other string) bool {
|
||||
return me.compareTo(other) == 1
|
||||
}
|
||||
|
||||
func (me Version) GreaterThanOrEqualTo(other string) bool {
|
||||
return me.compareTo(other) >= 0
|
||||
}
|
||||
|
||||
func (me Version) Equal(other string) bool {
|
||||
return me.compareTo(other) == 0
|
||||
}
|
25
version/version_test.go
Normal file
25
version/version_test.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func assertVersion(t *testing.T, a, b string, result int) {
|
||||
if r := Version(a).compareTo(b); r != result {
|
||||
t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareVersion(t *testing.T) {
|
||||
assertVersion(t, "1.12", "1.12", 0)
|
||||
assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1)
|
||||
assertVersion(t, "1", "1.0.1", -1)
|
||||
assertVersion(t, "1.0.1", "1", 1)
|
||||
assertVersion(t, "1.0.1", "1.0.2", -1)
|
||||
assertVersion(t, "1.0.2", "1.0.3", -1)
|
||||
assertVersion(t, "1.0.3", "1.1", -1)
|
||||
assertVersion(t, "1.1", "1.1.1", -1)
|
||||
assertVersion(t, "1.1.1", "1.1.2", -1)
|
||||
assertVersion(t, "1.1.2", "1.2", -1)
|
||||
|
||||
}
|
Loading…
Reference in a new issue