@@ -14,13 +14,17 @@ import (
14
14
. "github.com/onsi/ginkgo"
15
15
. "github.com/onsi/gomega"
16
16
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
17
+ "github.com/trivago/tgo/tcontainer"
17
18
"k8s.io/client-go/tools/clientcmd"
18
19
"k8s.io/client-go/tools/clientcmd/api"
19
20
21
+ "github.com/andygrunwald/go-jira"
20
22
"github.com/openshift/backplane-cli/pkg/backplaneapi"
21
23
backplaneapiMock "github.com/openshift/backplane-cli/pkg/backplaneapi/mocks"
22
24
"github.com/openshift/backplane-cli/pkg/cli/config"
23
25
"github.com/openshift/backplane-cli/pkg/client/mocks"
26
+ jiraClient "github.com/openshift/backplane-cli/pkg/jira"
27
+ jiraMock "github.com/openshift/backplane-cli/pkg/jira/mocks"
24
28
"github.com/openshift/backplane-cli/pkg/login"
25
29
"github.com/openshift/backplane-cli/pkg/ocm"
26
30
ocmMock "github.com/openshift/backplane-cli/pkg/ocm/mocks"
@@ -40,6 +44,7 @@ var _ = Describe("Login command", func() {
40
44
mockClientWithResp * mocks.MockClientWithResponsesInterface
41
45
mockOcmInterface * ocmMock.MockOCMInterface
42
46
mockClientUtil * backplaneapiMock.MockClientUtils
47
+ mockIssueService * jiraMock.MockIssueServiceInterface
43
48
44
49
testClusterID string
45
50
testToken string
@@ -576,4 +581,62 @@ var _ = Describe("Login command", func() {
576
581
})
577
582
578
583
})
584
+
585
+ Context ("check JIRA OHSS login" , func () {
586
+ var (
587
+ testOHSSID string
588
+ testIssue jira.Issue
589
+ issueFields * jira.IssueFields
590
+ )
591
+ BeforeEach (func () {
592
+ mockIssueService = jiraMock .NewMockIssueServiceInterface (mockCtrl )
593
+ ohssService = jiraClient .NewOHSSService (mockIssueService )
594
+ testOHSSID = "OHSS-1000"
595
+ })
596
+
597
+ It ("should login to ohss card cluster" , func () {
598
+
599
+ loginType = LoginTypeJira
600
+ args .ohss = testOHSSID
601
+ err := utils .CreateTempKubeConfig (nil )
602
+ args .kubeConfigPath = ""
603
+ Expect (err ).To (BeNil ())
604
+ issueFields = & jira.IssueFields {
605
+ Project : jira.Project {Key : jiraClient .JiraOHSSProjectKey },
606
+ Unknowns : tcontainer.MarshalMap {jiraClient .CustomFieldClusterID : testClusterID },
607
+ }
608
+ testIssue = jira.Issue {ID : testOHSSID , Fields : issueFields }
609
+ globalOpts .ProxyURL = "https://squid.myproxy.com"
610
+ mockIssueService .EXPECT ().Get (testOHSSID , nil ).Return (& testIssue , nil , nil ).Times (1 )
611
+ mockOcmInterface .EXPECT ().GetOCMEnvironment ().Return (ocmEnv , nil ).AnyTimes ()
612
+ mockClientUtil .EXPECT ().SetClientProxyURL (globalOpts .ProxyURL ).Return (nil )
613
+ mockOcmInterface .EXPECT ().GetTargetCluster (testClusterID ).Return (testClusterID , testClusterID , nil )
614
+ mockOcmInterface .EXPECT ().IsClusterHibernating (gomock .Eq (testClusterID )).Return (false , nil ).AnyTimes ()
615
+ mockOcmInterface .EXPECT ().GetOCMAccessToken ().Return (& testToken , nil )
616
+ mockClientUtil .EXPECT ().MakeRawBackplaneAPIClientWithAccessToken (backplaneAPIURI , testToken ).Return (mockClient , nil )
617
+ mockClient .EXPECT ().LoginCluster (gomock .Any (), gomock .Eq (testClusterID )).Return (fakeResp , nil )
618
+
619
+ err = runLogin (nil , nil )
620
+
621
+ Expect (err ).To (BeNil ())
622
+ })
623
+
624
+ It ("should failed missing cluster id ohss cards" , func () {
625
+
626
+ loginType = LoginTypeJira
627
+ args .ohss = testOHSSID
628
+
629
+ issueFields = & jira.IssueFields {
630
+ Project : jira.Project {Key : jiraClient .JiraOHSSProjectKey },
631
+ }
632
+ testIssue = jira.Issue {ID : testOHSSID , Fields : issueFields }
633
+ mockIssueService .EXPECT ().Get (testOHSSID , nil ).Return (& testIssue , nil , nil ).Times (1 )
634
+ mockOcmInterface .EXPECT ().GetOCMEnvironment ().Return (ocmEnv , nil ).AnyTimes ()
635
+
636
+ err := runLogin (nil , nil )
637
+
638
+ Expect (err ).NotTo (BeNil ())
639
+ Expect (err .Error ()).To (Equal ("clusterID cannot be detected for JIRA issue:OHSS-1000" ))
640
+ })
641
+ })
579
642
})
0 commit comments