github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/cmd/class/suite_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 class
    21  
    22  import (
    23  	"os"
    24  	"testing"
    25  
    26  	. "github.com/onsi/ginkgo/v2"
    27  	. "github.com/onsi/gomega"
    28  
    29  	corev1 "k8s.io/api/core/v1"
    30  	"k8s.io/apimachinery/pkg/util/yaml"
    31  	"k8s.io/client-go/kubernetes/scheme"
    32  
    33  	appsv1alpha1 "github.com/1aal/kubeblocks/apis/apps/v1alpha1"
    34  )
    35  
    36  const (
    37  	namespace                                        = "test"
    38  	testDefaultClassDefsPath                         = "../../testing/testdata/class.yaml"
    39  	testCustomClassDefsPath                          = "../../testing/testdata/custom_class.yaml"
    40  	testGeneralResourceConstraintPath                = "../../testing/testdata/resource-constraint-general.yaml"
    41  	testMemoryOptimizedResourceConstraintPath        = "../../testing/testdata/resource-constraint-memory-optimized.yaml"
    42  	testGeneralResourceConstraintWithoutSelectorPath = "../../testing/testdata/resource-constraint-general-without-selector.yaml"
    43  )
    44  
    45  var (
    46  	classDef                                 appsv1alpha1.ComponentClassDefinition
    47  	generalResourceConstraint                appsv1alpha1.ComponentResourceConstraint
    48  	generalResourceConstraintWithoutSelector appsv1alpha1.ComponentResourceConstraint
    49  	memoryOptimizedResourceConstraint        appsv1alpha1.ComponentResourceConstraint
    50  )
    51  
    52  var _ = BeforeSuite(func() {
    53  	var err error
    54  
    55  	classDefBytes, err := os.ReadFile(testDefaultClassDefsPath)
    56  	Expect(err).ShouldNot(HaveOccurred())
    57  	err = yaml.Unmarshal(classDefBytes, &classDef)
    58  	Expect(err).ShouldNot(HaveOccurred())
    59  
    60  	generalResourceConstraintBytes, err := os.ReadFile(testGeneralResourceConstraintPath)
    61  	Expect(err).ShouldNot(HaveOccurred())
    62  	err = yaml.Unmarshal(generalResourceConstraintBytes, &generalResourceConstraint)
    63  	Expect(err).ShouldNot(HaveOccurred())
    64  
    65  	generalResourceConstraintWithoutSelectorBytes, err := os.ReadFile(testGeneralResourceConstraintWithoutSelectorPath)
    66  	Expect(err).ShouldNot(HaveOccurred())
    67  	err = yaml.Unmarshal(generalResourceConstraintWithoutSelectorBytes, &generalResourceConstraintWithoutSelector)
    68  	Expect(err).ShouldNot(HaveOccurred())
    69  
    70  	memoryOptimizedResourceConstraintBytes, err := os.ReadFile(testMemoryOptimizedResourceConstraintPath)
    71  	Expect(err).ShouldNot(HaveOccurred())
    72  	err = yaml.Unmarshal(memoryOptimizedResourceConstraintBytes, &memoryOptimizedResourceConstraint)
    73  	Expect(err).ShouldNot(HaveOccurred())
    74  
    75  	err = appsv1alpha1.AddToScheme(scheme.Scheme)
    76  	Expect(err).ShouldNot(HaveOccurred())
    77  
    78  	err = corev1.AddToScheme(scheme.Scheme)
    79  	Expect(err).ShouldNot(HaveOccurred())
    80  
    81  })
    82  
    83  func TestClass(t *testing.T) {
    84  	RegisterFailHandler(Fail)
    85  	RunSpecs(t, "Class Suite")
    86  }