-
Notifications
You must be signed in to change notification settings - Fork 82
🌱 Fix integration tests and add comprehensive placement API tests #396
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
Merged
openshift-merge-bot
merged 1 commit into
open-cluster-management-io:main
from
qiujian16:fix/integration-tests-and-add-placement-api
Oct 16, 2025
Merged
Changes from all commits
Commits
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
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,184 @@ | ||
| // Copyright Contributors to the Open Cluster Management project | ||
| package api | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "k8s.io/apimachinery/pkg/api/errors" | ||
|
|
||
| "github.com/onsi/ginkgo" | ||
| "github.com/onsi/gomega" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/util/rand" | ||
| workv1 "open-cluster-management.io/api/work/v1" | ||
| ) | ||
|
|
||
| var _ = ginkgo.Describe("AppliedManifestWork v1 API test", func() { | ||
| var appliedManifestWorkName string | ||
|
|
||
| ginkgo.BeforeEach(func() { | ||
| suffix := rand.String(5) | ||
| appliedManifestWorkName = fmt.Sprintf("appliedmanifestwork-%s", suffix) | ||
| }) | ||
|
|
||
| ginkgo.AfterEach(func() { | ||
| err := hubWorkClient.WorkV1().AppliedManifestWorks().Delete(context.TODO(), appliedManifestWorkName, metav1.DeleteOptions{}) | ||
| if !errors.IsNotFound(err) { | ||
| gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
| } | ||
| }) | ||
|
|
||
| ginkgo.Context("AppliedManifestWork creation and validation", func() { | ||
| ginkgo.It("should create AppliedManifestWork with basic spec", func() { | ||
| appliedWork := &workv1.AppliedManifestWork{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: appliedManifestWorkName, | ||
| }, | ||
| Spec: workv1.AppliedManifestWorkSpec{ | ||
| HubHash: "test-hub-hash", | ||
| AgentID: "test-agent", | ||
| ManifestWorkName: "test-manifestwork", | ||
| }, | ||
| } | ||
|
|
||
| _, err := hubWorkClient.WorkV1().AppliedManifestWorks().Create(context.TODO(), appliedWork, metav1.CreateOptions{}) | ||
| gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
| }) | ||
|
|
||
| ginkgo.It("should handle AppliedManifestWork with applied resources", func() { | ||
| appliedWork := &workv1.AppliedManifestWork{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: appliedManifestWorkName, | ||
| }, | ||
| Spec: workv1.AppliedManifestWorkSpec{ | ||
| HubHash: "test-hub-hash", | ||
| AgentID: "test-agent", | ||
| ManifestWorkName: "test-manifestwork", | ||
| }, | ||
| } | ||
|
|
||
| _, err := hubWorkClient.WorkV1().AppliedManifestWorks().Create(context.TODO(), appliedWork, metav1.CreateOptions{}) | ||
| gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
| }) | ||
| }) | ||
|
|
||
| ginkgo.Context("AppliedManifestWork status validation", func() { | ||
| ginkgo.It("should allow status updates with applied resource status", func() { | ||
| appliedWork := &workv1.AppliedManifestWork{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: appliedManifestWorkName, | ||
| }, | ||
| Spec: workv1.AppliedManifestWorkSpec{ | ||
| HubHash: "test-hub-hash", | ||
| AgentID: "test-agent", | ||
| ManifestWorkName: "test-manifestwork", | ||
| }, | ||
| } | ||
|
|
||
| appliedManifestWork, err := hubWorkClient.WorkV1().AppliedManifestWorks().Create(context.TODO(), appliedWork, metav1.CreateOptions{}) | ||
| gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
|
|
||
| // Update status | ||
| appliedManifestWork.Status = workv1.AppliedManifestWorkStatus{ | ||
| AppliedResources: []workv1.AppliedManifestResourceMeta{ | ||
| { | ||
| ResourceIdentifier: workv1.ResourceIdentifier{ | ||
| Group: "", | ||
| Resource: "configmaps", | ||
| Name: "test-configmap", | ||
| Namespace: "default", | ||
| }, | ||
| Version: "v1", | ||
| UID: "test-uid-123", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, err = hubWorkClient.WorkV1().AppliedManifestWorks().UpdateStatus(context.TODO(), appliedManifestWork, metav1.UpdateOptions{}) | ||
| gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
| }) | ||
|
|
||
| ginkgo.It("should handle complex status with multiple resources", func() { | ||
| appliedWork := &workv1.AppliedManifestWork{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: appliedManifestWorkName, | ||
| }, | ||
| Spec: workv1.AppliedManifestWorkSpec{ | ||
| HubHash: "test-hub-hash", | ||
| AgentID: "test-agent", | ||
| ManifestWorkName: "test-manifestwork", | ||
| }, | ||
| } | ||
|
|
||
| appliedManifestWork, err := hubWorkClient.WorkV1().AppliedManifestWorks().Create(context.TODO(), appliedWork, metav1.CreateOptions{}) | ||
| gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
|
|
||
| // Update with complex status | ||
| appliedManifestWork.Status = workv1.AppliedManifestWorkStatus{ | ||
| AppliedResources: []workv1.AppliedManifestResourceMeta{ | ||
| { | ||
| ResourceIdentifier: workv1.ResourceIdentifier{ | ||
| Group: "", | ||
| Resource: "configmaps", | ||
| Name: "test-configmap", | ||
| Namespace: "default", | ||
| }, | ||
| Version: "v1", | ||
| UID: "configmap-uid-123", | ||
| }, | ||
| { | ||
| ResourceIdentifier: workv1.ResourceIdentifier{ | ||
| Group: "apps", | ||
| Resource: "deployments", | ||
| Name: "test-deployment", | ||
| Namespace: "default", | ||
| }, | ||
| Version: "v1", | ||
| UID: "deployment-uid-456", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| updatedWork, err := hubWorkClient.WorkV1().AppliedManifestWorks().UpdateStatus(context.TODO(), appliedManifestWork, metav1.UpdateOptions{}) | ||
| gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
| gomega.Expect(len(updatedWork.Status.AppliedResources)).Should(gomega.Equal(2)) | ||
| }) | ||
| }) | ||
|
|
||
| ginkgo.Context("AppliedManifestWork validation edge cases", func() { | ||
| ginkgo.It("should create with required fields", func() { | ||
| appliedWork := &workv1.AppliedManifestWork{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: appliedManifestWorkName, | ||
| }, | ||
| Spec: workv1.AppliedManifestWorkSpec{ | ||
| HubHash: "test-hub-hash", | ||
| AgentID: "test-agent", | ||
| ManifestWorkName: "test-manifestwork", | ||
| }, | ||
| } | ||
|
|
||
| createdAppliedWork, err := hubWorkClient.WorkV1().AppliedManifestWorks().Create(context.TODO(), appliedWork, metav1.CreateOptions{}) | ||
| gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
| gomega.Expect(createdAppliedWork.Spec.HubHash).Should(gomega.Equal("test-hub-hash")) | ||
| gomega.Expect(createdAppliedWork.Spec.AgentID).Should(gomega.Equal("test-agent")) | ||
| }) | ||
|
|
||
| ginkgo.It("should handle empty applied resources list", func() { | ||
| appliedWork := &workv1.AppliedManifestWork{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: appliedManifestWorkName, | ||
| }, | ||
| Spec: workv1.AppliedManifestWorkSpec{ | ||
| HubHash: "test-hub-hash", | ||
| AgentID: "test-agent", | ||
| ManifestWorkName: "test-manifestwork", | ||
| }, | ||
| } | ||
|
|
||
| appliedManifestWork, err := hubWorkClient.WorkV1().AppliedManifestWorks().Create(context.TODO(), appliedWork, metav1.CreateOptions{}) | ||
| gomega.Expect(err).ToNot(gomega.HaveOccurred()) | ||
| gomega.Expect(appliedManifestWork.Spec.HubHash).Should(gomega.Equal("test-hub-hash")) | ||
| }) | ||
| }) | ||
| }) |
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
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.
AfterEach should ignore NotFound as well
Avoid failing cleanup when the resource wasn’t created.
AfterEach(func() { err := operatorClient.OperatorV1().ClusterManagers().Delete(context.TODO(), clusterManagerName, metav1.DeleteOptions{}) - if !apierrors.IsForbidden(err) { - Expect(err).ToNot(HaveOccurred()) - } + if err != nil && !apierrors.IsForbidden(err) && !apierrors.IsNotFound(err) { + Expect(err).ToNot(HaveOccurred()) + } })📝 Committable suggestion
🤖 Prompt for AI Agents