Skip to content

Commit

Permalink
OCM-7535 | fix: change not found to info
Browse files Browse the repository at this point in the history
Signed-off-by: Maggie Chen <magchen@redhat.com>

rephrase

Signed-off-by: Maggie Chen <magchen@redhat.com>

fmt

Signed-off-by: Maggie Chen <magchen@redhat.com>

change text

Signed-off-by: Maggie Chen <magchen@redhat.com>

fix text

Signed-off-by: Maggie Chen <magchen@redhat.com>
  • Loading branch information
chenz4027 committed Apr 29, 2024
1 parent b2ab832 commit aae814b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
13 changes: 13 additions & 0 deletions cmd/list/breakglasscredential/breakglasscredential_suite_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 1 addition & 1 deletion cmd/list/breakglasscredential/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
42 changes: 42 additions & 0 deletions cmd/list/breakglasscredential/cmd_test.go
Original file line number Diff line number Diff line change
@@ -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"))
})
})
})
3 changes: 2 additions & 1 deletion cmd/list/externalauthprovider/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions cmd/list/externalauthprovider/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit aae814b

Please sign in to comment.