Skip to content

Commit 6812c92

Browse files
test(version): Migrate version_test.go to Ginkgo/Gomega (#5648)
* test(version): Migrate version_test.go to Ginkgo/Gomega Signed-off-by: Yuvraj Kolkar <kolkaryuvraj2@gmail.com> * test update Signed-off-by: Yuvraj Kolkar <kolkaryuvraj2@gmail.com> * update Signed-off-by: Yuvraj Kolkar <kolkaryuvraj2@gmail.com> --------- Signed-off-by: Yuvraj Kolkar <kolkaryuvraj2@gmail.com>
1 parent 3306b88 commit 6812c92

1 file changed

Lines changed: 36 additions & 54 deletions

File tree

pkg/utils/version/version_test.go

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,61 +16,43 @@ limitations under the License.
1616

1717
package version
1818

19-
import "testing"
20-
21-
func TestParse(t *testing.T) {
22-
validVersions := []string{
23-
"2.7.2-SNAPSHOT-3714f2b",
24-
"release-2.7.2-SNAPSHOT-3714f2b",
25-
"2.8.0",
26-
}
27-
28-
for _, s := range validVersions {
29-
t.Run(s, func(t *testing.T) {
30-
ver, err := RuntimeVersion(s)
31-
t.Log("Valid: ", s, ver, err)
32-
if err != nil {
33-
t.Errorf("RuntimeVersion unexpected error for version %q: %v", s, err)
34-
}
35-
})
36-
}
19+
import (
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
22+
"testing"
23+
)
24+
25+
func TestVersion(t *testing.T) {
26+
RegisterFailHandler(Fail)
27+
RunSpecs(t, "Version Suite")
3728
}
3829

39-
func TestCompare(t *testing.T) {
40-
tests := []struct {
41-
name string
42-
current string
43-
other string
44-
wantError bool
45-
want int
46-
}{
47-
{
48-
name: "lessThan",
49-
current: "release-2.7.2-SNAPSHOT-3714f2b",
50-
other: "2.8.0",
51-
wantError: false,
52-
want: -1,
30+
var _ = Describe("Version", func() {
31+
DescribeTable("RuntimeVersion",
32+
func(versionStr string) {
33+
ver, err := RuntimeVersion(versionStr)
34+
Expect(err).NotTo(HaveOccurred())
35+
Expect(ver).NotTo(BeNil())
36+
GinkgoWriter.Printf("Valid: %s, %v\n", versionStr, ver)
5337
},
54-
{
55-
name: "error",
56-
current: "test-2.7.2-SNAPSHOT-3714f2b",
57-
other: "2.8.0",
58-
wantError: true,
59-
want: 0,
60-
},
61-
}
62-
for _, tt := range tests {
63-
t.Run(tt.name, func(t *testing.T) {
64-
got, err := Compare(tt.current, tt.other)
65-
gotErr := err != nil
66-
if gotErr != tt.wantError {
67-
t.Errorf("testcase %v compare()'s expected error is %v, result is %v", tt.name, tt.wantError, err)
38+
Entry("should parse snapshot version", "2.7.2-SNAPSHOT-3714f2b"),
39+
Entry("should parse release snapshot version", "release-2.7.2-SNAPSHOT-3714f2b"),
40+
Entry("should parse simple version", "2.8.0"),
41+
)
42+
43+
DescribeTable("Compare",
44+
func(current, other string, expectedResult int, expectError bool) {
45+
result, err := Compare(current, other)
46+
if expectError {
47+
Expect(err).To(HaveOccurred())
48+
} else {
49+
Expect(err).NotTo(HaveOccurred())
6850
}
69-
70-
if got != tt.want {
71-
t.Errorf("testcase %v compare()'s expected value is %v, result is %v", tt.name, tt.want, got)
72-
}
73-
74-
})
75-
}
76-
}
51+
Expect(result).To(Equal(expectedResult))
52+
},
53+
Entry("should return -1 when current version is less than other", "release-2.7.2-SNAPSHOT-3714f2b", "2.8.0", -1, false),
54+
Entry("should return 0 when versions are equal", "2.8.0", "2.8.0", 0, false),
55+
Entry("should return 1 when current version is greater than other", "2.9.0", "2.8.0", 1, false),
56+
Entry("should return error for invalid version format", "test-2.7.2-SNAPSHOT-3714f2b", "2.8.0", 0, true),
57+
)
58+
})

0 commit comments

Comments
 (0)