Skip to content

Commit

Permalink
test: improve builder test coverage (#4009)
Browse files Browse the repository at this point in the history
  • Loading branch information
dengshaojiang authored Jun 28, 2023
1 parent 86ceea2 commit 30b27d6
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions internal/controller/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/spf13/viper"

"github.com/leaanthony/debme"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -534,6 +535,71 @@ var _ = Describe("builder", func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(job).ShouldNot(BeNil())
})

It("builds backup manifests job correctly", func() {
backup := &dataprotectionv1alpha1.Backup{}
podSpec := &corev1.PodSpec{
Containers: []corev1.Container{
{
Command: []string{"sh"},
},
},
}
key := types.NamespacedName{Name: "backup", Namespace: "default"}
job, err := BuildBackupManifestsJob(key, backup, podSpec)
Expect(err).Should(BeNil())
Expect(job).ShouldNot(BeNil())
Expect(job.Name).Should(Equal(key.Name))
})

It("builds restore job correctly", func() {
key := types.NamespacedName{Name: "restore", Namespace: "default"}
volumes := []corev1.Volume{}
volumeMounts := []corev1.VolumeMount{}
env := []corev1.EnvVar{}
job, err := BuildRestoreJob(key.Name, key.Namespace, "", []string{"sh"}, volumes, volumeMounts, env, nil)
Expect(err).Should(BeNil())
Expect(job).ShouldNot(BeNil())
Expect(job.Name).Should(Equal(key.Name))
})

It("builds volume snapshot class correctly", func() {
className := "vsc-test"
driverName := "csi-driver-test"
obj, err := BuildVolumeSnapshotClass(className, driverName)
Expect(err).Should(BeNil())
Expect(obj).ShouldNot(BeNil())
Expect(obj.Name).Should(Equal(className))
Expect(obj.Driver).Should(Equal(driverName))
})

It("builds headless svc correctly", func() {
_, cluster, synthesizedComponent := newClusterObjs(nil)
expectSvcName := fmt.Sprintf("%s-%s-headless", cluster.Name, synthesizedComponent.Name)
obj, err := BuildHeadlessSvc(cluster, synthesizedComponent)
Expect(err).Should(BeNil())
Expect(obj).ShouldNot(BeNil())
Expect(obj.Name).Should(Equal(expectSvcName))
})

It("builds cfg manager tools correctly", func() {
_, cluster, synthesizedComponent := newClusterObjs(nil)
cfgManagerParams := &cfgcm.CfgManagerBuildParams{
ManagerName: constant.ConfigSidecarName,
SecreteName: component.GenerateConnCredential(cluster.Name),
EnvConfigName: component.GenerateComponentEnvName(cluster.Name, synthesizedComponent.Name),
Image: viper.GetString(constant.KBToolsImage),
Cluster: cluster,
ConfigLazyRenderedVolumes: make(map[string]corev1.VolumeMount),
}
toolContainers := []appsv1alpha1.ToolConfig{
{Name: "test-tool", Image: "test-image", Command: []string{"sh"}},
}

obj, err := BuildCfgManagerToolsContainer(cfgManagerParams, synthesizedComponent, toolContainers)
Expect(err).Should(BeNil())
Expect(obj).ShouldNot(BeEmpty())
})
})

})

0 comments on commit 30b27d6

Please sign in to comment.