From aae814bd9f3e182008ba1ab72a0d2497a79f907c Mon Sep 17 00:00:00 2001 From: Maggie Chen Date: Mon, 29 Apr 2024 14:40:38 -0400 Subject: [PATCH] OCM-7535 | fix: change not found to info Signed-off-by: Maggie Chen rephrase Signed-off-by: Maggie Chen fmt Signed-off-by: Maggie Chen change text Signed-off-by: Maggie Chen fix text Signed-off-by: Maggie Chen --- .../breakglasscredential_suite_test.go | 13 ++++++ cmd/list/breakglasscredential/cmd.go | 2 +- cmd/list/breakglasscredential/cmd_test.go | 42 +++++++++++++++++++ cmd/list/externalauthprovider/cmd.go | 3 +- cmd/list/externalauthprovider/cmd_test.go | 8 ++-- 5 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 cmd/list/breakglasscredential/breakglasscredential_suite_test.go create mode 100644 cmd/list/breakglasscredential/cmd_test.go diff --git a/cmd/list/breakglasscredential/breakglasscredential_suite_test.go b/cmd/list/breakglasscredential/breakglasscredential_suite_test.go new file mode 100644 index 0000000000..c95528a03d --- /dev/null +++ b/cmd/list/breakglasscredential/breakglasscredential_suite_test.go @@ -0,0 +1,13 @@ +package breakglasscredential_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestBreakGlassCredential(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Breakglasscredential Suite") +} diff --git a/cmd/list/breakglasscredential/cmd.go b/cmd/list/breakglasscredential/cmd.go index b826f16528..adf6e3caf2 100644 --- a/cmd/list/breakglasscredential/cmd.go +++ b/cmd/list/breakglasscredential/cmd.go @@ -66,7 +66,7 @@ func runWithRuntime(r *rosa.Runtime, cmd *cobra.Command) error { } if len(breakGlassCredentials) == 0 { - r.Reporter.Infof("there are no break glass credentials for this cluster") + r.Reporter.Infof("There are no break glass credentials for cluster '%s'", clusterKey) return nil } diff --git a/cmd/list/breakglasscredential/cmd_test.go b/cmd/list/breakglasscredential/cmd_test.go new file mode 100644 index 0000000000..9100fd5cd5 --- /dev/null +++ b/cmd/list/breakglasscredential/cmd_test.go @@ -0,0 +1,42 @@ +package breakglasscredential + +import ( + "net/http" + + . "github.com/onsi/ginkgo/v2/dsl/core" + . "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("list break-glass-credential", func() { + var testRuntime test.TestingRuntime + + Context("List break glass credential command", func() { + mockClusterReady := test.MockCluster(func(c *cmv1.ClusterBuilder) { + c.AWS(cmv1.NewAWS().SubnetIDs("subnet-0b761d44d3d9a4663", "subnet-0f87f640e56934cbc")) + c.Region(cmv1.NewCloudRegion().ID("us-east-1")) + c.State(cmv1.ClusterStateReady) + c.Hypershift(cmv1.NewHypershift().Enabled(true)) + c.ExternalAuthConfig(cmv1.NewExternalAuthConfig().Enabled(true)) + }) + hypershiftClusterReady := test.FormatClusterList([]*cmv1.Cluster{mockClusterReady}) + + BeforeEach(func() { + testRuntime.InitRuntime() + // Reset flag to avoid any side effect on other tests + Cmd.Flags().Set("output", "") + }) + + It("Warning with zero results", func() { + testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, hypershiftClusterReady)) + testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusNotFound, "")) + stdout, stderr, err := test.RunWithOutputCapture(runWithRuntime, testRuntime.RosaRuntime, Cmd) + Expect(err).To(BeNil()) + Expect(stderr).To(Equal("")) + Expect(stdout).To(Equal("INFO: There are no break glass credentials for cluster 'cluster1'\n")) + }) + }) +}) diff --git a/cmd/list/externalauthprovider/cmd.go b/cmd/list/externalauthprovider/cmd.go index 9713cb2f4a..41aa5fe4aa 100644 --- a/cmd/list/externalauthprovider/cmd.go +++ b/cmd/list/externalauthprovider/cmd.go @@ -82,7 +82,8 @@ func runWithRuntime(r *rosa.Runtime, cmd *cobra.Command) error { } if len(externalAuthProviders) == 0 { - return fmt.Errorf("there are no external authentication providers for this cluster") + r.Reporter.Infof("There are no external authentication providers for cluster '%s'", clusterKey) + return nil } // Create the writer that will be used to print the tabulated results: diff --git a/cmd/list/externalauthprovider/cmd_test.go b/cmd/list/externalauthprovider/cmd_test.go index 819f50e471..998c1bd30b 100644 --- a/cmd/list/externalauthprovider/cmd_test.go +++ b/cmd/list/externalauthprovider/cmd_test.go @@ -65,15 +65,13 @@ var _ = Describe("list external-auth-provider", func() { Cmd.Flags().Set("output", "") }) - It("Fails with zero results", func() { + It("Warning with zero results", func() { testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, hypershiftClusterReady)) testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusNotFound, "")) stdout, stderr, err := test.RunWithOutputCapture(runWithRuntime, testRuntime.RosaRuntime, Cmd) - Expect(err).ToNot(BeNil()) - Expect(err.Error()).To( - ContainSubstring("there are no external authentication providers for this cluster")) + Expect(err).To(BeNil()) Expect(stderr).To(Equal("")) - Expect(stdout).To(Equal("")) + Expect(stdout).To(Equal("INFO: There are no external authentication providers for cluster 'cluster1'\n")) }) It("Returns error if not found", func() {