github.com/pmorton/docker@v1.5.0/pkg/version/version_test.go (about) 1 package version 2 3 import ( 4 "testing" 5 ) 6 7 func assertVersion(t *testing.T, a, b string, result int) { 8 if r := Version(a).compareTo(Version(b)); r != result { 9 t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result) 10 } 11 } 12 13 func TestCompareVersion(t *testing.T) { 14 assertVersion(t, "1.12", "1.12", 0) 15 assertVersion(t, "1.0.0", "1", 0) 16 assertVersion(t, "1", "1.0.0", 0) 17 assertVersion(t, "1.05.00.0156", "1.0.221.9289", 1) 18 assertVersion(t, "1", "1.0.1", -1) 19 assertVersion(t, "1.0.1", "1", 1) 20 assertVersion(t, "1.0.1", "1.0.2", -1) 21 assertVersion(t, "1.0.2", "1.0.3", -1) 22 assertVersion(t, "1.0.3", "1.1", -1) 23 assertVersion(t, "1.1", "1.1.1", -1) 24 assertVersion(t, "1.1.1", "1.1.2", -1) 25 assertVersion(t, "1.1.2", "1.2", -1) 26 27 }