-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test(dataprocess): migrate package tests and fix status handling #5739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hxrshxz
wants to merge
2
commits into
fluid-cloudnative:master
Choose a base branch
from
hxrshxz:test/dataprocess-ginkgo-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
pkg/controllers/v1alpha1/dataprocess/controller_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| Copyright 2026 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 dataprocess | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1" | ||
| "github.com/fluid-cloudnative/fluid/pkg/utils/fake" | ||
| v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/tools/record" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
| ) | ||
|
|
||
| // newTestDataProcessReconciler builds a DataProcessReconciler for unit tests. | ||
| func newTestDataProcessReconciler(s *runtime.Scheme, objs ...runtime.Object) *DataProcessReconciler { | ||
| if s == nil { | ||
| s = runtime.NewScheme() | ||
| _ = datav1alpha1.AddToScheme(s) | ||
| } | ||
| fakeClient := fake.NewFakeClientWithScheme(s, objs...) | ||
| log := logf.Log.WithName("dataprocess-test") | ||
| recorder := record.NewFakeRecorder(32) | ||
| return NewDataProcessReconciler(fakeClient, log, s, recorder) | ||
| } | ||
|
|
||
| var _ = Describe("DataProcessReconciler", func() { | ||
|
|
||
| Describe("ControllerName", func() { | ||
| It("should return the expected controller name", func() { | ||
| r := newTestDataProcessReconciler(nil) | ||
| Expect(r.ControllerName()).To(Equal("DataProcessReconciler")) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("NewDataProcessReconciler", func() { | ||
| It("should create a non-nil reconciler with a Scheme", func() { | ||
| s := runtime.NewScheme() | ||
| _ = datav1alpha1.AddToScheme(s) | ||
| r := newTestDataProcessReconciler(s) | ||
| Expect(r).NotTo(BeNil()) | ||
| Expect(r.Scheme).NotTo(BeNil()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("Build", func() { | ||
| It("should return a dataProcessOperation for a valid DataProcess object", func() { | ||
| r := newTestDataProcessReconciler(nil) | ||
| dp := &datav1alpha1.DataProcess{ | ||
| ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"}, | ||
| } | ||
| op, err := r.Build(dp) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(op).NotTo(BeNil()) | ||
| }) | ||
|
|
||
| It("should return an error when given a non-DataProcess object", func() { | ||
| r := newTestDataProcessReconciler(nil) | ||
| ds := &datav1alpha1.Dataset{ | ||
| ObjectMeta: v1.ObjectMeta{Name: "ds", Namespace: "default"}, | ||
| } | ||
| op, err := r.Build(ds) | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(op).To(BeNil()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("Reconcile", func() { | ||
| It("should return no error when the DataProcess is not found", func() { | ||
| s := runtime.NewScheme() | ||
| _ = datav1alpha1.AddToScheme(s) | ||
| r := newTestDataProcessReconciler(s) | ||
| // No DataProcess objects registered — should get NotFound and return cleanly. | ||
| req := ctrl.Request{ | ||
| NamespacedName: types.NamespacedName{Name: "missing", Namespace: "default"}, | ||
| } | ||
| result, err := r.Reconcile(context.TODO(), req) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(ctrl.Result{})) | ||
| }) | ||
|
|
||
| It("should reconcile successfully when DataProcess exists", func() { | ||
| s := runtime.NewScheme() | ||
| _ = datav1alpha1.AddToScheme(s) | ||
| dp := &datav1alpha1.DataProcess{ | ||
| ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"}, | ||
| Spec: datav1alpha1.DataProcessSpec{ | ||
| Dataset: datav1alpha1.TargetDatasetWithMountPath{ | ||
| TargetDataset: datav1alpha1.TargetDataset{ | ||
| Name: "ds", | ||
| Namespace: "default", | ||
| }, | ||
| MountPath: "/data", | ||
| }, | ||
| Processor: datav1alpha1.Processor{ | ||
| Script: &datav1alpha1.ScriptProcessor{ | ||
| Source: "echo hello", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| r := newTestDataProcessReconciler(s, dp) | ||
| req := ctrl.Request{ | ||
| NamespacedName: types.NamespacedName{Name: "test", Namespace: "default"}, | ||
| } | ||
| result, err := r.Reconcile(context.TODO(), req) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(result).To(Equal(ctrl.Result{RequeueAfter: 20 * time.Second})) | ||
| }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The potential error from
datav1alpha1.AddToScheme(s)is ignored. In a test helper, it's better to panic on error to cause an immediate and clear test failure. This ensures the test setup is robust. A similar issue of ignoring errors fromAddToSchemeexists on lines 60, 92, and 105, whereExpect(...).To(Succeed())should be used to be consistent with other tests in this PR.