github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/util/version_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 util 21 22 import ( 23 . "github.com/onsi/ginkgo/v2" 24 . "github.com/onsi/gomega" 25 26 "k8s.io/client-go/kubernetes" 27 28 "github.com/1aal/kubeblocks/pkg/cli/testing" 29 ) 30 31 const kbVersion = "0.3.0" 32 33 var _ = Describe("version util", func() { 34 It("get version info when client is nil", func() { 35 v, err := GetVersionInfo(nil) 36 Expect(err).Should(Succeed()) 37 Expect(v.KubeBlocks).Should(BeEmpty()) 38 Expect(v.Kubernetes).Should(BeEmpty()) 39 Expect(v.Cli).ShouldNot(BeEmpty()) 40 }) 41 42 It("get version info when client variable is a nil pointer", func() { 43 var client *kubernetes.Clientset 44 v, err := GetVersionInfo(client) 45 Expect(err).Should(Succeed()) 46 Expect(v.KubeBlocks).Should(BeEmpty()) 47 Expect(v.Kubernetes).Should(BeEmpty()) 48 Expect(v.Cli).ShouldNot(BeEmpty()) 49 }) 50 51 It("get version info when KubeBlocks is deployed", func() { 52 client := testing.FakeClientSet(testing.FakeKBDeploy(kbVersion)) 53 v, err := GetVersionInfo(client) 54 Expect(err).Should(Succeed()) 55 Expect(v.KubeBlocks).Should(Equal(kbVersion)) 56 Expect(v.Kubernetes).ShouldNot(BeEmpty()) 57 Expect(v.Cli).ShouldNot(BeEmpty()) 58 }) 59 60 It("get version info when KubeBlocks is not deployed", func() { 61 client := testing.FakeClientSet() 62 v, err := GetVersionInfo(client) 63 Expect(err).Should(Succeed()) 64 Expect(v.KubeBlocks).Should(BeEmpty()) 65 Expect(v.Kubernetes).ShouldNot(BeEmpty()) 66 Expect(v.Cli).ShouldNot(BeEmpty()) 67 }) 68 69 It("getKubeBlocksVersion", func() { 70 client := testing.FakeClientSet(testing.FakeKBDeploy("")) 71 v, err := getKubeBlocksVersion(client) 72 Expect(v).Should(BeEmpty()) 73 Expect(err).Should(HaveOccurred()) 74 75 client = testing.FakeClientSet(testing.FakeKBDeploy(kbVersion)) 76 v, err = getKubeBlocksVersion(client) 77 Expect(v).Should(Equal(kbVersion)) 78 Expect(err).Should(Succeed()) 79 }) 80 81 It("GetK8sVersion when client is nil", func() { 82 v, err := GetK8sVersion(nil) 83 Expect(v).Should(BeEmpty()) 84 Expect(err).Should(Succeed()) 85 }) 86 87 It("GetK8sVersion", func() { 88 client := testing.FakeClientSet() 89 v, err := GetK8sVersion(client.Discovery()) 90 Expect(v).ShouldNot(BeEmpty()) 91 Expect(err).Should(Succeed()) 92 }) 93 })