github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/cmd/context/context_text.go (about)

     1  /*
     2  Copyright (C) 2022-2023 ApeCloud Co., Ltd
     3  
     4  This file is part of KubeBlocks project
     5  
     6  This program is free software: you can redistribute it and/or modify
     7  it under the terms of the GNU Affero General Public License as published by
     8  the Free Software Foundation, either version 3 of the License, or
     9  (at your option) any later version.
    10  
    11  This program is distributed in the hope that it will be useful
    12  but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  GNU Affero General Public License for more details.
    15  
    16  You should have received a copy of the GNU Affero General Public License
    17  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18  */
    19  
    20  package context
    21  
    22  import (
    23  	ginkgo_context "github.com/onsi/ginkgo/v2"
    24  	. "github.com/onsi/gomega"
    25  
    26  	"k8s.io/cli-runtime/pkg/genericiooptions"
    27  
    28  	"github.com/1aal/kubeblocks/pkg/cli/cmd/organization"
    29  )
    30  
    31  type MockContext struct {
    32  	genericiooptions.IOStreams
    33  }
    34  
    35  func (m *MockContext) showContext() error {
    36  	return nil
    37  }
    38  
    39  func (m *MockContext) showContexts() error {
    40  	return nil
    41  }
    42  
    43  func (m *MockContext) showCurrentContext() error {
    44  	return nil
    45  }
    46  
    47  func (m *MockContext) showUseContext() error {
    48  	return nil
    49  }
    50  
    51  func (m *MockContext) showRemoveContext() error {
    52  	return nil
    53  }
    54  
    55  var _ = ginkgo_context.Describe("Test Cloud Context", func() {
    56  	var (
    57  		streams genericiooptions.IOStreams
    58  		o       *ContextOptions
    59  	)
    60  	ginkgo_context.BeforeEach(func() {
    61  		streams, _, _, _ = genericiooptions.NewTestIOStreams()
    62  		o = &ContextOptions{
    63  			ContextName: "test_context",
    64  			Context: &MockContext{
    65  				IOStreams: streams,
    66  			},
    67  			IOStreams: streams,
    68  		}
    69  	})
    70  
    71  	ginkgo_context.AfterEach(func() {
    72  	})
    73  
    74  	ginkgo_context.Context("test context", func() {
    75  		Expect(organization.SetCurrentOrgAndContext(&organization.CurrentOrgAndContext{
    76  			CurrentOrganization: "test_org",
    77  			CurrentContext:      "test_context",
    78  		})).Should(BeNil())
    79  
    80  		args := []string{"test_context"}
    81  		ginkgo_context.It("test context list ", func() {
    82  			cmd := newContextListCmd(streams)
    83  			Expect(o.complete(args)).Should(Succeed())
    84  			Expect(o.validate(cmd)).Should(Succeed())
    85  			Expect(o.runList()).Should(Succeed())
    86  		})
    87  
    88  		ginkgo_context.It("test context current ", func() {
    89  			cmd := newContextCurrentCmd(streams)
    90  			Expect(o.complete(args)).Should(Succeed())
    91  			Expect(o.validate(cmd)).Should(Succeed())
    92  			Expect(o.runCurrent()).Should(Succeed())
    93  		})
    94  
    95  		ginkgo_context.It("test context describe ", func() {
    96  			cmd := newContextDescribeCmd(streams)
    97  			Expect(o.complete(args)).Should(Succeed())
    98  			Expect(o.validate(cmd)).Should(Succeed())
    99  			Expect(o.runDescribe()).Should(Succeed())
   100  		})
   101  
   102  		ginkgo_context.It("test context use ", func() {
   103  			cmd := newContextUseCmd(streams)
   104  			Expect(o.complete(args)).Should(Succeed())
   105  			Expect(o.validate(cmd)).Should(Succeed())
   106  			Expect(o.runUse()).Should(Succeed())
   107  		})
   108  	})
   109  })