-
Notifications
You must be signed in to change notification settings - Fork 253
ROSAENG-60112 | test: add tests for delete cluster command #3298
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
openshift:master
from
olucasfreitas:ROSAENG-60112-2B
Jul 1, 2026
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,13 @@ | ||
| package cluster | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| func TestDeleteCluster(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| RunSpecs(t, "Delete cluster suite") | ||
| } |
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,187 @@ | ||
| package cluster | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" | ||
| . "github.com/openshift-online/ocm-sdk-go/testing" | ||
|
|
||
| "github.com/openshift/rosa/pkg/test" | ||
| ) | ||
|
|
||
| var _ = Describe("Delete cluster", func() { | ||
| var ( | ||
| t *test.TestingRuntime | ||
| clusterId string | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| t = test.NewTestRuntime() | ||
| clusterId = test.MockClusterID | ||
| }) | ||
|
|
||
| Context("handleClusterDelete", func() { | ||
| It("returns nil and logs info when the cluster is already uninstalling", func() { | ||
| clusterReady := test.MockCluster(func(c *cmv1.ClusterBuilder) { | ||
| c.State(cmv1.ClusterStateReady) | ||
| }) | ||
| t.SetCluster(clusterId, clusterReady) | ||
|
|
||
| statusBody := fmt.Sprintf(`{ | ||
| "kind": "ClusterStatus", | ||
| "id": "%s", | ||
| "state": "uninstalling" | ||
| }`, clusterId) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, statusBody)) | ||
|
|
||
| err := t.StdOutReader.Record() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| err = handleClusterDelete(t.RosaRuntime, clusterReady, clusterId, false) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
olucasfreitas marked this conversation as resolved.
|
||
|
|
||
| stdout, err := t.StdOutReader.Read() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(stdout).To(ContainSubstring("already uninstalling")) | ||
| }) | ||
|
|
||
| It("deletes the cluster and logs the start message", func() { | ||
| clusterReady := test.MockCluster(func(c *cmv1.ClusterBuilder) { | ||
| c.State(cmv1.ClusterStateReady) | ||
| }) | ||
| t.SetCluster(clusterId, clusterReady) | ||
|
|
||
| statusBody := fmt.Sprintf(`{ | ||
| "kind": "ClusterStatus", | ||
| "id": "%s", | ||
| "state": "ready" | ||
| }`, clusterId) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, statusBody)) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON( | ||
| http.StatusOK, test.FormatClusterList([]*cmv1.Cluster{clusterReady}))) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, "")) | ||
|
|
||
| err := t.StdOutReader.Record() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| err = handleClusterDelete(t.RosaRuntime, clusterReady, clusterId, false) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| stdout, err := t.StdOutReader.Read() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(stdout).To(ContainSubstring("will start uninstalling")) | ||
| }) | ||
|
|
||
| It("passes the bestEffort flag through to DeleteCluster", func() { | ||
| clusterReady := test.MockCluster(func(c *cmv1.ClusterBuilder) { | ||
| c.State(cmv1.ClusterStateReady) | ||
| }) | ||
| t.SetCluster(clusterId, clusterReady) | ||
|
|
||
| statusBody := fmt.Sprintf(`{ | ||
| "kind": "ClusterStatus", | ||
| "id": "%s", | ||
| "state": "ready" | ||
| }`, clusterId) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, statusBody)) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON( | ||
| http.StatusOK, test.FormatClusterList([]*cmv1.Cluster{clusterReady}))) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, "")) | ||
|
|
||
| err := handleClusterDelete(t.RosaRuntime, clusterReady, clusterId, true) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
olucasfreitas marked this conversation as resolved.
|
||
| }) | ||
|
olucasfreitas marked this conversation as resolved.
|
||
|
|
||
| It("returns an error when GetClusterState fails", func() { | ||
| clusterReady := test.MockCluster(func(c *cmv1.ClusterBuilder) { | ||
| c.State(cmv1.ClusterStateReady) | ||
| }) | ||
| t.SetCluster(clusterId, clusterReady) | ||
|
|
||
| t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusInternalServerError, "")) | ||
|
|
||
| err := handleClusterDelete(t.RosaRuntime, clusterReady, clusterId, false) | ||
| Expect(err).To(HaveOccurred()) | ||
|
olucasfreitas marked this conversation as resolved.
|
||
| Expect(err.Error()).To(ContainSubstring("expected response content type")) | ||
| }) | ||
|
|
||
| It("returns an error when DeleteCluster fails", func() { | ||
| clusterReady := test.MockCluster(func(c *cmv1.ClusterBuilder) { | ||
| c.State(cmv1.ClusterStateReady) | ||
| }) | ||
| t.SetCluster(clusterId, clusterReady) | ||
|
|
||
| statusBody := fmt.Sprintf(`{ | ||
| "kind": "ClusterStatus", | ||
| "id": "%s", | ||
| "state": "ready" | ||
| }`, clusterId) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, statusBody)) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON( | ||
| http.StatusOK, test.FormatClusterList([]*cmv1.Cluster{clusterReady}))) | ||
| t.ApiServer.AppendHandlers(RespondWithJSON(http.StatusForbidden, `{ | ||
| "kind": "Error", | ||
| "id": "403", | ||
| "href": "/api/clusters_mgmt/v1/errors/403", | ||
| "code": "CLUSTERS-MGMT-403", | ||
| "reason": "forbidden" | ||
| }`)) | ||
|
|
||
| err := handleClusterDelete(t.RosaRuntime, clusterReady, clusterId, false) | ||
| Expect(err).To(HaveOccurred()) | ||
|
olucasfreitas marked this conversation as resolved.
|
||
| Expect(err.Error()).To(ContainSubstring("forbidden")) | ||
| }) | ||
| }) | ||
|
|
||
| Context("buildCommands", func() { | ||
| It("uses cluster ID flags when OIDC config is not reusable", func() { | ||
| cluster := test.MockCluster(func(c *cmv1.ClusterBuilder) { | ||
| c.AWS(cmv1.NewAWS().STS( | ||
| cmv1.NewSTS(). | ||
| RoleARN("arn:aws:iam::123456789012:role/Installer"). | ||
| OperatorRolePrefix("my-prefix"). | ||
| OIDCEndpointURL("https://oidc.example.com"). | ||
| OperatorIAMRoles( | ||
| cmv1.NewOperatorIAMRole(). | ||
| Name("ebs-cloud-credentials"). | ||
| Namespace("openshift-cluster-csi-drivers"). | ||
| RoleARN("arn:aws:iam::123456789012:role/op-role"), | ||
| ), | ||
| )) | ||
| }) | ||
|
|
||
| result := buildCommands(cluster) | ||
| Expect(result).To(ContainSubstring(fmt.Sprintf("-c %s", clusterId))) | ||
| Expect(result).To(ContainSubstring("rosa delete operator-roles")) | ||
| Expect(result).To(ContainSubstring("rosa delete oidc-provider")) | ||
| Expect(result).NotTo(ContainSubstring("--prefix")) | ||
| Expect(result).NotTo(ContainSubstring("--oidc-config-id")) | ||
| }) | ||
|
|
||
| It("uses prefix and oidc-config-id flags when OIDC config is reusable", func() { | ||
| cluster := test.MockCluster(func(c *cmv1.ClusterBuilder) { | ||
| c.AWS(cmv1.NewAWS().STS( | ||
| cmv1.NewSTS(). | ||
| RoleARN("arn:aws:iam::123456789012:role/Installer"). | ||
| OperatorRolePrefix("my-prefix"). | ||
| OIDCEndpointURL("https://oidc.example.com"). | ||
| OidcConfig(cmv1.NewOidcConfig().ID("oidc-abc123").Reusable(true)). | ||
| OperatorIAMRoles( | ||
| cmv1.NewOperatorIAMRole(). | ||
| Name("ebs-cloud-credentials"). | ||
| Namespace("openshift-cluster-csi-drivers"). | ||
| RoleARN("arn:aws:iam::123456789012:role/op-role"), | ||
| ), | ||
| )) | ||
| }) | ||
|
|
||
| result := buildCommands(cluster) | ||
| Expect(result).To(ContainSubstring("--prefix my-prefix")) | ||
| Expect(result).To(ContainSubstring("--oidc-config-id oidc-abc123")) | ||
| Expect(result).NotTo(ContainSubstring(fmt.Sprintf("-c %s", clusterId))) | ||
| }) | ||
| }) | ||
| }) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.