-
Notifications
You must be signed in to change notification settings - Fork 1
fix(#12): correct elevate command in service login prompt #13
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -398,6 +398,36 @@ var _ = Describe("Login command", func() { | |
| Expect(err).To(BeNil()) | ||
| }) | ||
|
|
||
| It("should print correct elevate command with -n flag and ocm-backplane binary name for service login", func() { | ||
| globalOpts.Service = true | ||
| err := utils.CreateTempKubeConfig(nil) | ||
| Expect(err).To(BeNil()) | ||
| mockOcmInterface.EXPECT().GetOCMEnvironment().Return(ocmEnv, nil).AnyTimes() | ||
| mockOcmInterface.EXPECT().GetTargetCluster(testClusterID).Return(trueClusterID, testClusterID, nil) | ||
| mockOcmInterface.EXPECT().GetManagingCluster(trueClusterID).Return(managingClusterID, managingClusterID, true, nil).AnyTimes() | ||
| mockOcmInterface.EXPECT().GetServiceCluster(trueClusterID).Return(serviceClusterID, serviceClusterName, nil) | ||
| mockOcmInterface.EXPECT().IsClusterHibernating(gomock.Eq(serviceClusterID)).Return(false, nil).AnyTimes() | ||
| mockOcmInterface.EXPECT().GetOCMAccessToken().Return(&testToken, nil) | ||
| mockClientUtil.EXPECT().MakeRawBackplaneAPIClientWithAccessToken(backplaneAPIURI, testToken).Return(mockClient, nil) | ||
| mockClient.EXPECT().LoginCluster(gomock.Any(), gomock.Eq(serviceClusterID)).Return(fakeResp, nil) | ||
|
|
||
| // Capture stdout to verify the elevate command output | ||
| old := os.Stdout | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] test-quality os.Stdout is reassigned without a deferred restore. If runLogin or io.ReadAll panics, os.Stdout remains pointed at a closed pipe, corrupting subsequent test output. The os.Pipe() error is also silently discarded. Suggested fix: Use 'defer func() { os.Stdout = old }()' immediately after saving the old value, and check the error from os.Pipe(). |
||
| r, w, _ := os.Pipe() | ||
| os.Stdout = w | ||
|
|
||
| err = runLogin(nil, []string{testClusterID}) | ||
|
|
||
| w.Close() | ||
| out, _ := io.ReadAll(r) | ||
| os.Stdout = old | ||
|
|
||
| Expect(err).To(BeNil()) | ||
| output := string(out) | ||
| Expect(output).To(ContainSubstring("ocm-backplane elevate -n --")) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] test-quality The test assertions only check for substring presence of 'ocm-backplane elevate -n --' and absence of 'ocm backplane elevate --', but don't detect the double-'oc' bug. The assertions should verify the full command pattern including what follows '--'. Suggested fix: Add assertion: Expect(output).To(ContainSubstring("-- get manifestworks")) and Expect(output).NotTo(ContainSubstring("-- oc ")) |
||
| Expect(output).NotTo(ContainSubstring("ocm backplane elevate --")) | ||
| }) | ||
|
|
||
| It("should login to current cluster if cluster id not provided", func() { | ||
| loginType = LoginTypeExistingKubeConfig | ||
| err := utils.CreateTempKubeConfig(nil) | ||
|
|
||
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.
[high] correctness
The printed elevate command includes 'oc' after '--', but with the '-n' flag, 'oc' is no longer consumed as the reason argument. The elevate command internally prepends 'oc' via exec.Command("oc", argv[1:]...), so the resulting execution would be 'oc oc get manifestworks...' which fails. All documented examples (CONTRIBUTING.md, README.md) confirm that 'oc' should NOT appear after '--'.
Suggested fix: Remove 'oc' from the format string: fmt.Sprintf("ocm-backplane elevate -n -- get manifestworks -n %s -l api.openshift.com/id=%s", managingClusterName, targetClusterID)