Skip to content

test(api/v1alpha1): migrate core API tests to Ginkgo#5889

Open
hxrshxz wants to merge 4 commits into
fluid-cloudnative:masterfrom
hxrshxz:test/api-v1alpha1-ginkgo-core
Open

test(api/v1alpha1): migrate core API tests to Ginkgo#5889
hxrshxz wants to merge 4 commits into
fluid-cloudnative:masterfrom
hxrshxz:test/api-v1alpha1-ginkgo-core

Conversation

@hxrshxz
Copy link
Copy Markdown
Contributor

@hxrshxz hxrshxz commented May 17, 2026

Ⅰ. Describe what this PR does

Migrate the core api/v1alpha1 unit tests in scope to Ginkgo v2 + Gomega and add focused coverage for common API helper behavior.

Ⅱ. Does this pull request fix one issue?

#5676

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

  • Convert dataset operation reference tests to Ginkgo v2 + Gomega.
  • Convert IsHostNetwork coverage to Ginkgo v2 + Gomega.
  • Add MetadataSyncPolicy.AutoSyncEnabled() coverage for default/nil, explicit true, and explicit false.
  • Add Dataset.CanbeBound() and Dataset.IsExclusiveMode() coverage.

Ⅳ. Describe how to verify it

Run the api/v1alpha1 unit tests and confirm the migrated Ginkgo suite passes with only the intended test files changed.

Ⅴ. Special notes for reviews

N/A

Signed-off-by: Harsh <harshmastic@gmail.com>
Copilot AI review requested due to automatic review settings May 17, 2026 10:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates existing api/v1alpha1 unit tests from the standard testing table-driven style to Ginkgo v2 + Gomega, and adds new focused coverage for several common API helpers. A Ginkgo test suite entrypoint is introduced so the existing and new specs run under the migrated framework.

Changes:

  • Add suite_test.go to bootstrap a Ginkgo suite for the v1alpha1 package.
  • Convert dataset_types_test.go and container_network_test.go to Describe/DescribeTable specs.
  • Add new common_test.go covering MetadataSyncPolicy.AutoSyncEnabled, Dataset.CanbeBound, and Dataset.IsExclusiveMode.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
api/v1alpha1/suite_test.go New Ginkgo suite entrypoint for the package.
api/v1alpha1/dataset_types_test.go Reworks Remove/Set/GetDataOperationInProgress tests as DescribeTable specs.
api/v1alpha1/container_network_test.go Reworks IsHostNetwork tests to DescribeTable, replacing the literal "" case with DefaultNetworkMode.
api/v1alpha1/common_test.go Adds new specs for AutoSyncEnabled, CanbeBound, and IsExclusiveMode.
Comments suppressed due to low confidence (1)

api/v1alpha1/common_test.go:14

  • The license header has stray leading tabs/indentation on lines 5–14 (each line is prefixed with a tab). Other license headers in this PR and across the repo (e.g., api/v1alpha1/suite_test.go, container_network.go) place these lines at column 0. The indentation should be removed for consistency.
	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.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,82 @@
/*
Copyright 2026 The Fluid Authors.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the unit tests in the api/v1alpha1 package from the standard Go testing package to the Ginkgo and Gomega BDD framework, while also adding new tests for common API helpers. The review feedback suggests improving the test coverage for CanbeBound and IsExclusiveMode by utilizing DescribeTable to verify all components of the runtime identity and all placement modes explicitly.

Comment thread api/v1alpha1/common_test.go Outdated
Comment on lines +48 to +67
Describe("Dataset.CanbeBound", func() {
It("returns true when no runtime is recorded", func() {
dataset := &Dataset{}

Expect(dataset.CanbeBound("runtime", "fluid", common.AccelerateCategory)).To(BeTrue())
})

It("returns true only for a matching runtime identity", func() {
dataset := &Dataset{
Status: DatasetStatus{
Runtimes: []Runtime{
{Name: "target", Namespace: "fluid", Category: common.AccelerateCategory},
},
},
}

Expect(dataset.CanbeBound("target", "fluid", common.AccelerateCategory)).To(BeTrue())
Expect(dataset.CanbeBound("other", "fluid", common.AccelerateCategory)).To(BeFalse())
})
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test coverage for CanbeBound can be improved by verifying all components of the runtime identity (Name, Namespace, and Category). Using a DescribeTable would make this more thorough and readable by explicitly testing mismatch scenarios for each field.

	Describe("Dataset.CanbeBound", func() {
		It("returns true when no runtime is recorded", func() {
			dataset := &Dataset{}

			Expect(dataset.CanbeBound("runtime", "fluid", common.AccelerateCategory)).To(BeTrue())
		})

		DescribeTable("matching runtime identity",
			func(name, ns string, cat common.Category, expected bool) {
				dataset := &Dataset{
					Status: DatasetStatus{
						Runtimes: []Runtime{
							{Name: "target", Namespace: "fluid", Category: common.AccelerateCategory},
						},
					},
				}
				Expect(dataset.CanbeBound(name, ns, cat)).To(Equal(expected))
			},
			Entry("matching identity", "target", "fluid", common.AccelerateCategory, true),
			Entry("name mismatch", "other", "fluid", common.AccelerateCategory, false),
			Entry("namespace mismatch", "target", "other", common.AccelerateCategory, false),
			Entry("category mismatch", "target", "fluid", common.Category("other"), false),
		)
	})

Comment thread api/v1alpha1/common_test.go Outdated
Comment on lines +69 to +81
Describe("Dataset.IsExclusiveMode", func() {
It("treats default placement as exclusive", func() {
dataset := &Dataset{}

Expect(dataset.IsExclusiveMode()).To(BeTrue())
})

It("returns false for shared placement mode", func() {
dataset := &Dataset{Spec: DatasetSpec{PlacementMode: ShareMode}}

Expect(dataset.IsExclusiveMode()).To(BeFalse())
})
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The tests for IsExclusiveMode should explicitly cover the ExclusiveMode case as well, as it is one of the two conditions that return true in the implementation. Refactoring to a DescribeTable improves clarity and ensures all placement modes are accounted for.

	DescribeTable("Dataset.IsExclusiveMode",
		func(mode PlacementMode, expected bool) {
			dataset := &Dataset{Spec: DatasetSpec{PlacementMode: mode}}
			Expect(dataset.IsExclusiveMode()).To(Equal(expected))
		},
		Entry("treats default placement as exclusive", DefaultMode, true),
		Entry("treats explicit exclusive mode as exclusive", ExclusiveMode, true),
		Entry("returns false for shared placement mode", ShareMode, false),
	)

@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.65%. Comparing base (ed9b7ef) to head (515154a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5889   +/-   ##
=======================================
  Coverage   61.65%   61.65%           
=======================================
  Files         480      480           
  Lines       32613    32613           
=======================================
  Hits        20108    20108           
  Misses      10897    10897           
  Partials     1608     1608           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Harsh <harshmastic@gmail.com>
@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot Bot commented May 17, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign cheyang for approval by writing /assign @cheyang in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hxrshxz hxrshxz requested a review from Copilot May 17, 2026 11:50
@hxrshxz
Copy link
Copy Markdown
Contributor Author

hxrshxz commented May 17, 2026

/gemini review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread api/v1alpha1/common_test.go Outdated
@@ -0,0 +1,47 @@
/*
Copyright 2020 The Fluid Authors.
Comment on lines +29 to 33
DescribeTable("removes the target operation reference",
func(dataset *Dataset, operationType string, name string, expected string) {
Expect(dataset.RemoveDataOperationInProgress(operationType, name)).To(Equal(expected))
Expect(dataset.GetDataOperationInProgress(operationType)).To(Equal(expected))
},
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the unit tests in the api/v1alpha1 package from the standard Go testing package to the Ginkgo and Gomega BDD framework. The changes include the addition of a test suite entry point, new tests for MetadataSyncPolicy, and the refactoring of existing tests for IsHostNetwork and Dataset methods into DescribeTable formats. Feedback suggests improving the naming of the top-level Describe block in dataset_types_test.go to better encompass all tested methods and wrapping the IsExclusiveMode table in a Describe block for better structural consistency.

Comment thread api/v1alpha1/dataset_types_test.go Outdated
Status: DatasetStatus{},
const dataLoadOperation = "DataLoad"

var _ = Describe("Dataset operation references", func() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The top-level Describe block name "Dataset operation references" is too narrow, as the suite now includes tests for CanbeBound and IsExclusiveMode which are unrelated to operation references. Consider renaming it to something more inclusive like "Dataset methods" or simply "Dataset".

Comment thread api/v1alpha1/dataset_types_test.go Outdated
Comment on lines +115 to +124
DescribeTable("IsExclusiveMode",
func(mode PlacementMode, expected bool) {
dataset := &Dataset{Spec: DatasetSpec{PlacementMode: mode}}

Expect(dataset.IsExclusiveMode()).To(Equal(expected))
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dataset := &Dataset{
TypeMeta: tt.fields.TypeMeta,
ObjectMeta: tt.fields.ObjectMeta,
Spec: tt.fields.Spec,
Status: tt.fields.Status,
}
dataset.SetDataOperationInProgress(tt.args.operationType, tt.args.name)
if got := dataset.GetDataOperationInProgress(tt.args.operationType); got != tt.want {
t.Errorf("SetDataOperationInProgress() = %v, want %v", got, tt.want)
}
})
}
}
Entry("default placement mode", DefaultMode, true),
Entry("exclusive placement mode", ExclusiveMode, true),
Entry("shared placement mode", ShareMode, false),
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other test blocks in this file and to provide better context, consider wrapping the IsExclusiveMode table in a Describe block and using a more descriptive string for the table itself.

	Describe("IsExclusiveMode", func() {
		DescribeTable("reports whether the placement mode is exclusive",
			func(mode PlacementMode, expected bool) {
				dataset := &Dataset{Spec: DatasetSpec{PlacementMode: mode}}

				Expect(dataset.IsExclusiveMode()).To(Equal(expected))
			},
			Entry("default placement mode", DefaultMode, true),
			Entry("exclusive placement mode", ExclusiveMode, true),
			Entry("shared placement mode", ShareMode, false),
		)
	})

Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz
Copy link
Copy Markdown
Contributor Author

hxrshxz commented May 17, 2026

/gemini review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the unit tests for the v1alpha1 API package to use the Ginkgo and Gomega testing frameworks. It introduces a test suite, converts existing table-driven tests for network modes and dataset operations to Ginkgo's DescribeTable format, and adds new test coverage for metadata sync policies and dataset binding logic. Feedback was provided to simplify the test parameters in RemoveDataOperationInProgress by removing redundant variables to improve maintainability.

Comment on lines +30 to 33
func(dataset *Dataset, operationType string, name string, expectedRemoved string, expectedCurrent string) {
Expect(dataset.RemoveDataOperationInProgress(operationType, name)).To(Equal(expectedRemoved))
Expect(dataset.GetDataOperationInProgress(operationType)).To(Equal(expectedCurrent))
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The expectedRemoved and expectedCurrent parameters in this table-driven test are redundant because RemoveDataOperationInProgress returns the updated state of the operation reference, which is exactly what GetDataOperationInProgress retrieves. Simplifying this to a single expected parameter would improve test maintainability.

Suggested change
func(dataset *Dataset, operationType string, name string, expectedRemoved string, expectedCurrent string) {
Expect(dataset.RemoveDataOperationInProgress(operationType, name)).To(Equal(expectedRemoved))
Expect(dataset.GetDataOperationInProgress(operationType)).To(Equal(expectedCurrent))
},
func(dataset *Dataset, operationType string, name string, expected string) {
Expect(dataset.RemoveDataOperationInProgress(operationType, name)).To(Equal(expected))
Expect(dataset.GetDataOperationInProgress(operationType)).To(Equal(expected))
},

@hxrshxz
Copy link
Copy Markdown
Contributor Author

hxrshxz commented May 17, 2026

/gemini review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the unit tests for the api/v1alpha1 package, migrating from the standard library's testing package to the Ginkgo and Gomega frameworks. Key changes include the addition of a test suite setup, the conversion of existing tests to DescribeTable formats, and the introduction of new tests for MetadataSyncPolicy, CanbeBound, and IsExclusiveMode. Feedback from the review focuses on improving code maintainability by using constants for operation types and increasing test coverage for edge cases in operation removal logic.

Comment thread api/v1alpha1/dataset_types_test.go Outdated
name: "test3",
fields: fields{
Status: DatasetStatus{},
const dataLoadOperation = "DataLoad"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better maintainability and consistency, consider defining a constant for the 'DataMigrate' operation type, similar to how dataLoadOperation is defined.

const (
	dataLoadOperation    = "DataLoad"
	dataMigrateOperation = "DataMigrate"
)

Comment on lines +48 to +54
Entry("returns empty when no operation refs are recorded",
&Dataset{Status: DatasetStatus{}},
dataLoadOperation,
"test1",
"",
"",
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Adding a test case for the scenario where the operation to be removed is not present in the OperationRef list would improve the coverage of edge cases for RemoveDataOperationInProgress.

			Entry("returns empty when no operation refs are recorded",
				&Dataset{Status: DatasetStatus{}},
				dataLoadOperation,
				"test1",
				"",
				"",
			),
			Entry("returns original list when operation is not found",
				&Dataset{Status: DatasetStatus{OperationRef: map[string]string{dataLoadOperation: "test1,test2"}}},
				dataLoadOperation,
				"test3",
				"test1,test2",
				"test1,test2",
			),

Comment thread api/v1alpha1/dataset_types_test.go Outdated
),
Entry("records a different operation type independently",
&Dataset{Status: DatasetStatus{OperationRef: map[string]string{dataLoadOperation: "test1"}}},
"DataMigrate",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the newly defined constant for consistency.

Suggested change
"DataMigrate",
dataMigrateOperation,

Signed-off-by: Harsh <harshmastic@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants