-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCM-7871 | fix: Mandatory fields should enter interactive mode if not…
… provided Signed-off-by: Maggie Chen <[email protected]> add tests Signed-off-by: Maggie Chen <[email protected]>
- Loading branch information
Showing
3 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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,54 @@ | ||
package externalauthprovider | ||
|
||
import ( | ||
"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("ExternalAuthProvider Create Tests", func() { | ||
var testRuntime test.TestingRuntime | ||
|
||
Context("Create 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("KO: Should ask for interactive mode if params are not passed", func() { | ||
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, hypershiftClusterReady)) | ||
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusNotFound, "")) | ||
stdout, stderr, err := test.RunWithOutputCaptureAndArgv(runWithRuntime, testRuntime.RosaRuntime, Cmd, &[]string{}) | ||
Expect(err).To(HaveOccurred()) | ||
Expect(stderr).To(Equal("")) | ||
Expect(stdout).To(Equal("INFO: Enabling interactive mode\n\x1b[0G\x1b[2K? " + | ||
"Name: [? for help] \x1b[?25l\x1b[?25l\x1b7\x1b[999;999f\x1b[6n\x1b8\x1b[?25h\x1b[6n\x1b[?25h")) | ||
}) | ||
|
||
It("KO: Should ask for interactive mode if all mandatory fields are not given", func() { | ||
Cmd.Flags().Set("name", "test-name") | ||
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusOK, hypershiftClusterReady)) | ||
testRuntime.ApiServer.AppendHandlers(RespondWithJSON(http.StatusNotFound, "")) | ||
stdout, stderr, err := test.RunWithOutputCaptureAndArgv(runWithRuntime, testRuntime.RosaRuntime, Cmd, &[]string{}) | ||
Expect(err).To(HaveOccurred()) | ||
Expect(stderr).To(Equal("")) | ||
Expect(stdout).To(Equal("\x1b[0G\x1b[2K? Issuer audiences: [? for help]" + | ||
" \x1b[?25l\x1b[?25l\x1b7\x1b[999;999f\x1b[6n\x1b8\x1b[?25h\x1b[6n\x1b[?25h")) | ||
}) | ||
}) | ||
}) |
29 changes: 29 additions & 0 deletions
29
cmd/create/externalauthprovider/externalauthprovider_suite_test.go
This file contains 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,29 @@ | ||
/* | ||
Copyright (c) 2024 Red Hat, Inc. | ||
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 externalauthprovider | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestIdp(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "ExternalAuthProvider Create Suite") | ||
} |
This file contains 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