From 1c2728868003086b1cbb0acc856f88dbb9867f99 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Fri, 30 Jun 2017 09:47:31 -0700 Subject: [PATCH] Adds tests for versioncmp functions Relates to issues raised in #4156 Signed-off-by: Eli Uriegas --- libmachine/versioncmp/compare_test.go | 192 ++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/libmachine/versioncmp/compare_test.go b/libmachine/versioncmp/compare_test.go index 1840aacfca..cd7a9d907f 100644 --- a/libmachine/versioncmp/compare_test.go +++ b/libmachine/versioncmp/compare_test.go @@ -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) + } + } +}