From ae6d0ab2abc2df3e162830ec140767d68a1839cf Mon Sep 17 00:00:00 2001 From: fullsend-code <278716306+fullsend-ai-coder[bot]@users.noreply.github.com> Date: Tue, 14 Jul 2026 21:35:39 +0000 Subject: [PATCH] fix(#12): correct elevate command in service login prompt The service login prompt printed an incorrect elevate command with two issues: it used 'ocm backplane' instead of the shipped binary name 'ocm-backplane', and it was missing the -n flag (--no-reason) that prompts the user for an elevation reason. Fix the format string to use the correct binary name and include the -n flag. Add a test that captures stdout during service login and asserts the correct command format is printed. Closes #12 --- cmd/ocm-backplane/login/login.go | 2 +- cmd/ocm-backplane/login/login_test.go | 30 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/cmd/ocm-backplane/login/login.go b/cmd/ocm-backplane/login/login.go index 97d83081..d9bbdd63 100644 --- a/cmd/ocm-backplane/login/login.go +++ b/cmd/ocm-backplane/login/login.go @@ -288,7 +288,7 @@ func runLogin(cmd *cobra.Command, argv []string) (err error) { if !isHostedControlPlane { return fmt.Errorf("manifestworks are only available for hosted control plane clusters") } - listManifestWork := fmt.Sprintf("ocm backplane elevate -- oc get manifestworks -n %s -l api.openshift.com/id=%s", managingClusterName, targetClusterID) + listManifestWork := fmt.Sprintf("ocm-backplane elevate -n -- oc get manifestworks -n %s -l api.openshift.com/id=%s", managingClusterName, targetClusterID) fmt.Println("A list of associated manifestwork for your given cluster can be found using:") fmt.Println("\t", listManifestWork) diff --git a/cmd/ocm-backplane/login/login_test.go b/cmd/ocm-backplane/login/login_test.go index 64ad2f99..4457e721 100644 --- a/cmd/ocm-backplane/login/login_test.go +++ b/cmd/ocm-backplane/login/login_test.go @@ -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 + 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 --")) + 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)