github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/preflight/analyzer/analyze_result_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 analyzer
    21  
    22  import (
    23  	. "github.com/onsi/ginkgo/v2"
    24  	. "github.com/onsi/gomega"
    25  
    26  	troubleshoot "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
    27  )
    28  
    29  var _ = Describe("kb_storage_class_test", func() {
    30  	var (
    31  		outcomes []*troubleshoot.Outcome
    32  	)
    33  	Context("analyze storage class test", func() {
    34  		BeforeEach(func() {
    35  			outcomes = []*troubleshoot.Outcome{
    36  				{
    37  					Pass: &troubleshoot.SingleOutcome{
    38  
    39  						Message: "analyze storage class success",
    40  					},
    41  					Fail: &troubleshoot.SingleOutcome{
    42  						Message: "analyze storage class fail",
    43  					},
    44  					Warn: &troubleshoot.SingleOutcome{
    45  						Message: "warn message",
    46  					},
    47  				},
    48  			}
    49  		})
    50  		It("AnalyzeResult test, and expected that fail is true", func() {
    51  			Eventually(func(g Gomega) {
    52  				res := newAnalyzeResult("test", FailType, outcomes)
    53  				g.Expect(res.IsFail).Should(BeTrue())
    54  				g.Expect(res.Message).Should(Equal(outcomes[0].Fail.Message))
    55  			}).Should(Succeed())
    56  		})
    57  
    58  		It("AnalyzeResult test, and expected that warn is true", func() {
    59  			Eventually(func(g Gomega) {
    60  				res := newAnalyzeResult("test", WarnType, outcomes)
    61  				g.Expect(res.IsWarn).Should(BeTrue())
    62  				g.Expect(res.Message).Should(Equal(outcomes[0].Warn.Message))
    63  			}).Should(Succeed())
    64  		})
    65  		It("AnalyzeResult test, and expected that pass is true", func() {
    66  			Eventually(func(g Gomega) {
    67  				res := newAnalyzeResult("test", PassType, outcomes)
    68  				g.Expect(res.IsPass).Should(BeTrue())
    69  				g.Expect(res.Message).Should(Equal(outcomes[0].Pass.Message))
    70  			}).Should(Succeed())
    71  		})
    72  		It("AnalyzeResult with message test, and expected that fail is true", func() {
    73  			Eventually(func(g Gomega) {
    74  				message := "test"
    75  				res := newFailedResultWithMessage("test", message)
    76  				g.Expect(res.IsFail).Should(BeTrue())
    77  				g.Expect(res.Message).Should(Equal(message))
    78  			}).Should(Succeed())
    79  		})
    80  		It("AnalyzeResult with message test, and expected that fail is true", func() {
    81  			Eventually(func(g Gomega) {
    82  				message := "test"
    83  				res := newWarnResultWithMessage("test", message)
    84  				g.Expect(res.IsWarn).Should(BeTrue())
    85  				g.Expect(res.Message).Should(Equal(message))
    86  			}).Should(Succeed())
    87  		})
    88  	})
    89  })