github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/cluster/cluster_chart_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 cluster
    21  
    22  import (
    23  	. "github.com/onsi/ginkgo/v2"
    24  	. "github.com/onsi/gomega"
    25  )
    26  
    27  var _ = Describe("cluster engine", func() {
    28  	const (
    29  		clusterType = "mysql"
    30  		name        = "test-cluster"
    31  		namespace   = "test-namespace"
    32  		kubeVersion = "v99.99.0"
    33  	)
    34  
    35  	It("get and validate engine helm chart", func() {
    36  		By("unsupported engine type")
    37  		_, err := BuildChartInfo("unsupported")
    38  		Expect(err).Should(HaveOccurred())
    39  
    40  		By("build cluster chart info")
    41  		c, err := BuildChartInfo(clusterType)
    42  		Expect(err).Should(Succeed())
    43  		Expect(c).ShouldNot(BeNil())
    44  		Expect(c.Schema).ShouldNot(BeNil())
    45  		Expect(c.SubSchema).ShouldNot(BeNil())
    46  		Expect(c.SubChartName).ShouldNot(BeEmpty())
    47  
    48  		By("get manifests")
    49  		manifests, err := GetManifests(c.Chart, namespace, name, kubeVersion, nil)
    50  		Expect(err).Should(Succeed())
    51  		Expect(manifests).ShouldNot(BeEmpty())
    52  
    53  		By("validate values")
    54  		testCases := []struct {
    55  			desc    string
    56  			values  map[string]interface{}
    57  			success bool
    58  		}{
    59  			{
    60  				"cpu is greater than maximum",
    61  				map[string]interface{}{
    62  					"cpu": 1000,
    63  				},
    64  				// cpu should greater than 0.1
    65  				false,
    66  			},
    67  			{
    68  				"terminationPolicy is unknown",
    69  				map[string]interface{}{
    70  					"terminationPolicy": "unknown",
    71  				},
    72  				// "unknown" is not a valid value
    73  				false,
    74  			},
    75  			{
    76  				"all values are valid",
    77  				map[string]interface{}{
    78  					"cpu":               1.0,
    79  					"terminationPolicy": "Halt",
    80  				},
    81  				true,
    82  			},
    83  		}
    84  		for _, tc := range testCases {
    85  			By(tc.desc)
    86  			err = ValidateValues(c, tc.values)
    87  			if tc.success {
    88  				Expect(err).Should(Succeed())
    89  			} else {
    90  				Expect(err).Should(HaveOccurred())
    91  			}
    92  		}
    93  	})
    94  })