Skip to content

Commit

Permalink
Merge pull request docker#4162 from seemethere/add_comparison_functio…
Browse files Browse the repository at this point in the history
…n_tests

Adds tests for versioncmp functions
  • Loading branch information
FrenchBen authored Jun 30, 2017
2 parents 255980c + 1c27288 commit d8dd388
Showing 1 changed file with 192 additions and 0 deletions.
192 changes: 192 additions & 0 deletions libmachine/versioncmp/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,195 @@ func TestCompare(t *testing.T) {
}
}
}

func TestLessThan(t *testing.T) {
cases := []struct {
v1, v2 string
want bool
}{
{"1.12", "1.12", false},
{"1.0.0", "1", false},
{"1", "1.0.0", false},
{"1.05.00.0156", "1.0.221.9289", false},
{"1", "1.0.1", true},
{"1.0.1", "1", false},
{"1.0.1", "1.0.2", true},
{"1.0.2", "1.0.3", true},
{"1.0.3", "1.1", true},
{"1.1", "1.1.1", true},
{"1.a", "1.b", false},
{"1.a", "2.b", true},
{"1.1", "1.1.0", false},
{"1.1.1", "1.1.2", true},
{"1.1.2", "1.2", true},
{"1.12.1", "1.13.0-rc1", true},
{"1.13.0-rc1", "1.13.0-rc2", true},
{"1.13.0-rc1", "1.13.1-rc1", true},
{"17.03.0-ce", "17.03.0-ce", false},
{"17.03.1-ce", "17.03.2-ce", true},
{"17.06.6-ce", "17.09.2-ce", true},
{"17.03.0-ce", "17.06.0-ce", true},
{"17.03.0-ce-rc2", "17.03.0-ce-rc1", false},
{"17.03.0-ce-rc1", "18.03.0-ce-rc1", true},
{"17.06.0-ce", "1.12.0", false},
}
for _, tc := range cases {
if got := LessThan(tc.v1, tc.v2); got != tc.want {
t.Errorf("LessThan(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want)
}
}
}

func TestLessThanOrEqualTo(t *testing.T) {
cases := []struct {
v1, v2 string
want bool
}{
{"1.12", "1.12", true},
{"1.0.0", "1", true},
{"1", "1.0.0", true},
{"1.05.00.0156", "1.0.221.9289", false},
{"1", "1.0.1", true},
{"1.0.1", "1", false},
{"1.0.1", "1.0.2", true},
{"1.0.2", "1.0.3", true},
{"1.0.3", "1.1", true},
{"1.1", "1.1.1", true},
{"1.a", "1.b", true},
{"1.a", "2.b", true},
{"1.1", "1.1.0", true},
{"1.1.1", "1.1.2", true},
{"1.1.2", "1.2", true},
{"1.12.1", "1.13.0-rc1", true},
{"1.13.0-rc1", "1.13.0-rc2", true},
{"1.13.0-rc1", "1.13.1-rc1", true},
{"17.03.0-ce", "17.03.0-ce", true},
{"17.03.1-ce", "17.03.2-ce", true},
{"17.06.6-ce", "17.09.2-ce", true},
{"17.03.0-ce", "17.06.0-ce", true},
{"17.03.0-ce-rc2", "17.03.0-ce-rc1", false},
{"17.03.0-ce-rc1", "18.03.0-ce-rc1", true},
{"17.06.0-ce", "1.12.0", false},
}
for _, tc := range cases {
if got := LessThanOrEqualTo(tc.v1, tc.v2); got != tc.want {
t.Errorf("LessThanOrEqualTo(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want)
}
}
}

func TestGreaterThan(t *testing.T) {
cases := []struct {
v1, v2 string
want bool
}{
{"1.12", "1.12", false},
{"1.0.0", "1", false},
{"1", "1.0.0", false},
{"1.05.00.0156", "1.0.221.9289", true},
{"1", "1.0.1", false},
{"1.0.1", "1", true},
{"1.0.1", "1.0.2", false},
{"1.0.2", "1.0.3", false},
{"1.0.3", "1.1", false},
{"1.1", "1.1.1", false},
{"1.a", "1.b", false},
{"1.a", "2.b", false},
{"1.1", "1.1.0", false},
{"1.1.1", "1.1.2", false},
{"1.1.2", "1.2", false},
{"1.12.1", "1.13.0-rc1", false},
{"1.13.0-rc1", "1.13.0-rc2", false},
{"1.13.0-rc1", "1.13.1-rc1", false},
{"17.03.0-ce", "17.03.0-ce", false},
{"17.03.1-ce", "17.03.2-ce", false},
{"17.06.6-ce", "17.09.2-ce", false},
{"17.03.0-ce", "17.06.0-ce", false},
{"17.03.0-ce-rc2", "17.03.0-ce-rc1", true},
{"17.03.0-ce-rc1", "18.03.0-ce-rc1", false},
{"17.06.0-ce", "1.12.0", true},
}
for _, tc := range cases {
if got := GreaterThan(tc.v1, tc.v2); got != tc.want {
t.Errorf("GreaterThan(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want)
}
}
}

func TestGreaterThanOrEqualTo(t *testing.T) {
cases := []struct {
v1, v2 string
want bool
}{
{"1.12", "1.12", true},
{"1.0.0", "1", true},
{"1", "1.0.0", true},
{"1.05.00.0156", "1.0.221.9289", true},
{"1", "1.0.1", false},
{"1.0.1", "1", true},
{"1.0.1", "1.0.2", false},
{"1.0.2", "1.0.3", false},
{"1.0.3", "1.1", false},
{"1.1", "1.1.1", false},
{"1.a", "1.b", true},
{"1.a", "2.b", false},
{"1.1", "1.1.0", true},
{"1.1.1", "1.1.2", false},
{"1.1.2", "1.2", false},
{"1.12.1", "1.13.0-rc1", false},
{"1.13.0-rc1", "1.13.0-rc2", false},
{"1.13.0-rc1", "1.13.1-rc1", false},
{"17.03.0-ce", "17.03.0-ce", true},
{"17.03.1-ce", "17.03.2-ce", false},
{"17.06.6-ce", "17.09.2-ce", false},
{"17.03.0-ce", "17.06.0-ce", false},
{"17.03.0-ce-rc2", "17.03.0-ce-rc1", true},
{"17.03.0-ce-rc1", "18.03.0-ce-rc1", false},
{"17.06.0-ce", "1.12.0", true},
}
for _, tc := range cases {
if got := GreaterThanOrEqualTo(tc.v1, tc.v2); got != tc.want {
t.Errorf("GreaterThanOrEqualTo(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want)
}
}
}

func TestEqual(t *testing.T) {
cases := []struct {
v1, v2 string
want bool
}{
{"1.12", "1.12", true},
{"1.0.0", "1", true},
{"1", "1.0.0", true},
{"1.05.00.0156", "1.0.221.9289", false},
{"1", "1.0.1", false},
{"1.0.1", "1", false},
{"1.0.1", "1.0.2", false},
{"1.0.2", "1.0.3", false},
{"1.0.3", "1.1", false},
{"1.1", "1.1.1", false},
{"1.a", "1.b", true},
{"1.a", "2.b", false},
{"1.1", "1.1.0", true},
{"1.1.1", "1.1.2", false},
{"1.1.2", "1.2", false},
{"1.12.1", "1.13.0-rc1", false},
{"1.13.0-rc1", "1.13.0-rc2", false},
{"1.13.0-rc1", "1.13.1-rc1", false},
{"17.03.0-ce", "17.03.0-ce", true},
{"17.03.1-ce", "17.03.2-ce", false},
{"17.06.6-ce", "17.09.2-ce", false},
{"17.03.0-ce", "17.06.0-ce", false},
{"17.03.0-ce-rc2", "17.03.0-ce-rc1", false},
{"17.03.0-ce-rc1", "18.03.0-ce-rc1", false},
{"17.06.0-ce-rc2", "1.12.0", false},
{"1.12.0", "17.06.0-ce-rc2", false},
{"17.06.0-ce", "1.12.0", false},
}
for _, tc := range cases {
if got := Equal(tc.v1, tc.v2); got != tc.want {
t.Errorf("Equal(%q, %q) == %v, want %v", tc.v1, tc.v2, got, tc.want)
}
}
}

0 comments on commit d8dd388

Please sign in to comment.