From d814efa31b4f78604d63021985700d2cbb8fb814 Mon Sep 17 00:00:00 2001 From: wangyelei Date: Mon, 2 Dec 2024 15:21:04 +0800 Subject: [PATCH] add test case --- controllers/apps/cluster_controller_test.go | 5 +++++ pkg/controller/factory/builder_test.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/controllers/apps/cluster_controller_test.go b/controllers/apps/cluster_controller_test.go index 7e99498b4c1..ccdd425a777 100644 --- a/controllers/apps/cluster_controller_test.go +++ b/controllers/apps/cluster_controller_test.go @@ -405,6 +405,11 @@ var _ = Describe("Cluster Controller", func() { constant.KBAppShardingNameLabelKey: compName, } Eventually(testapps.List(&testCtx, generics.ComponentSignature, ml, client.InNamespace(clusterKey.Namespace))).Should(HaveLen(shards)) + + By("checking the sharding name label") + compList := &appsv1.ComponentList{} + Expect(k8sClient.List(ctx, compList, ml)).Should(Succeed()) + Expect(compList.Items[0].Spec.Labels[constant.KBAppShardingNameLabelKey]).Should(Equal(compName)) } testClusterComponentScaleIn := func(compName, compDefName string) { diff --git a/pkg/controller/factory/builder_test.go b/pkg/controller/factory/builder_test.go index 30de73608c7..2f668ab421c 100644 --- a/pkg/controller/factory/builder_test.go +++ b/pkg/controller/factory/builder_test.go @@ -43,6 +43,7 @@ var _ = Describe("builder", func() { const compDefName = "test-compdef" const clusterName = "test-cluster" const mysqlCompName = "mysql" + const dynamicLabel = "dynamic" allFieldsCompDefObj := func(needCreate bool) *appsv1.ComponentDefinition { By("By assure an componentDefinition obj") @@ -78,6 +79,9 @@ var _ = Describe("builder", func() { newAllFieldsSynthesizedComponent := func(compDef *appsv1.ComponentDefinition, cluster *appsv1.Cluster) *component.SynthesizedComponent { By("assign every available fields") comp, err := component.BuildComponent(cluster, &cluster.Spec.ComponentSpecs[0], nil, nil) + comp.Spec.Labels = map[string]string{ + dynamicLabel: dynamicLabel, + } Expect(err).Should(Succeed()) synthesizeComp, err := component.BuildSynthesizedComponent(testCtx.Ctx, testCtx.Cli, compDef, comp, cluster) Expect(err).Should(Succeed()) @@ -101,6 +105,7 @@ var _ = Describe("builder", func() { compDef, cluster, synthesizedComponent := newClusterObjs(nil) its, err := BuildInstanceSet(synthesizedComponent, nil) + Expect(its.Labels).Should(HaveKey(dynamicLabel)) Expect(err).Should(BeNil()) Expect(its).ShouldNot(BeNil())