github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/cmd/playground/init_test.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 playground
    21  
    22  import (
    23  	"os"
    24  
    25  	. "github.com/onsi/ginkgo/v2"
    26  	. "github.com/onsi/gomega"
    27  
    28  	gv "github.com/hashicorp/go-version"
    29  	"k8s.io/cli-runtime/pkg/genericiooptions"
    30  
    31  	cp "github.com/1aal/kubeblocks/pkg/cli/cloudprovider"
    32  	clitesting "github.com/1aal/kubeblocks/pkg/cli/testing"
    33  	"github.com/1aal/kubeblocks/pkg/cli/types"
    34  	"github.com/1aal/kubeblocks/pkg/cli/util/helm"
    35  	"github.com/1aal/kubeblocks/version"
    36  )
    37  
    38  var _ = Describe("playground", func() {
    39  	const (
    40  		testKubeConfigPath = "./testdata/kubeconfig"
    41  	)
    42  
    43  	var streams genericiooptions.IOStreams
    44  
    45  	BeforeEach(func() {
    46  		streams, _, _, _ = genericiooptions.NewTestIOStreams()
    47  		Expect(os.Setenv(types.CliHomeEnv, "./testdata")).Should(Succeed())
    48  	})
    49  
    50  	It("init at local host", func() {
    51  		cmd := newInitCmd(streams)
    52  		Expect(cmd != nil).Should(BeTrue())
    53  
    54  		o := &initOptions{
    55  			clusterDef:     clitesting.ClusterDefName,
    56  			clusterVersion: clitesting.ClusterVersionName,
    57  			IOStreams:      streams,
    58  			cloudProvider:  defaultCloudProvider,
    59  			helmCfg:        helm.NewConfig("", testKubeConfigPath, "", false),
    60  			dockerVersion:  version.MinimumDockerVersion,
    61  		}
    62  		Expect(o.validate()).Should(Succeed())
    63  		Expect(o.run()).Should(HaveOccurred())
    64  		Expect(o.installKubeBlocks("test")).Should(HaveOccurred())
    65  		Expect(o.createCluster()).Should(HaveOccurred())
    66  	})
    67  
    68  	It("init at local host without outdate docker", func() {
    69  		var err error
    70  		o := &initOptions{
    71  			clusterDef:     clitesting.ClusterDefName,
    72  			clusterVersion: clitesting.ClusterVersionName,
    73  			IOStreams:      streams,
    74  			cloudProvider:  defaultCloudProvider,
    75  			helmCfg:        helm.NewConfig("", testKubeConfigPath, "", false),
    76  		}
    77  		o.dockerVersion, err = gv.NewVersion("20.10.0")
    78  		Expect(err).Should(BeNil())
    79  		Expect(o.validate()).Should(HaveOccurred())
    80  	})
    81  
    82  	It("init at remote cloud", func() {
    83  		o := &initOptions{
    84  			IOStreams:      streams,
    85  			clusterDef:     clitesting.ClusterDefName,
    86  			clusterVersion: clitesting.ClusterVersionName,
    87  			cloudProvider:  cp.AWS,
    88  		}
    89  		Expect(o.validate()).Should(HaveOccurred())
    90  	})
    91  })