From 3568720904a8cece094982b2bd6b3b03c3a9220e Mon Sep 17 00:00:00 2001 From: SUBID DAS Date: Sat, 31 Jan 2026 17:07:27 +0530 Subject: [PATCH] test(common): migrate constants_test.go to Ginkgo/Gomega Migrate pkg/common/constants_test.go from testing.T to Ginkgo v2 and Gomega for BDD-style testing. Changes: - Add common_suite_test.go for Ginkgo test suite setup - Convert table-driven test to Ginkgo DescribeTable/Entry - Use explicit ginkgo/gomega imports to avoid naming conflicts Part of #5407 Signed-off-by: SUBID DAS --- pkg/common/common_suite_test.go | 29 +++++++++++++++++++++++ pkg/common/constants_test.go | 42 ++++++++++----------------------- 2 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 pkg/common/common_suite_test.go diff --git a/pkg/common/common_suite_test.go b/pkg/common/common_suite_test.go new file mode 100644 index 00000000000..6249de7ecfe --- /dev/null +++ b/pkg/common/common_suite_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2021 The Fluid Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "testing" + + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" +) + +func TestCommon(t *testing.T) { + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Package Common Suite") +} diff --git a/pkg/common/constants_test.go b/pkg/common/constants_test.go index eb94ee3b449..bf7fec4cbbd 100644 --- a/pkg/common/constants_test.go +++ b/pkg/common/constants_test.go @@ -17,36 +17,18 @@ limitations under the License. package common import ( - "testing" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" ) -func TestGetDefaultTieredStoreOrder(t *testing.T) { - testCases := map[string]struct { - mediumType MediumType - want int - }{ - "test case 1": { - mediumType: Memory, - want: 0, +var _ = ginkgo.Describe("GetDefaultTieredStoreOrder", func() { + ginkgo.DescribeTable("should return correct order for medium types", + func(mediumType MediumType, expectedOrder int) { + gomega.Expect(GetDefaultTieredStoreOrder(mediumType)).To(gomega.Equal(expectedOrder)) }, - "test case 2": { - mediumType: SSD, - want: 1, - }, - "test case 3": { - mediumType: HDD, - want: 2, - }, - "test case 4": { - mediumType: "unknown", - want: 0, - }, - } - for k, item := range testCases { - result := GetDefaultTieredStoreOrder(item.mediumType) - if item.want != result { - t.Errorf("%s cannot paas, want %v, get %v", k, item.want, result) - } - } - -} + ginkgo.Entry("Memory returns 0", Memory, 0), + ginkgo.Entry("SSD returns 1", SSD, 1), + ginkgo.Entry("HDD returns 2", HDD, 2), + ginkgo.Entry("unknown returns 0", MediumType("unknown"), 0), + ) +})