Skip to content

Commit

Permalink
fix: testcase error
Browse files Browse the repository at this point in the history
  • Loading branch information
fengluodb committed Oct 11, 2023
1 parent 4dc2c3d commit 0cc9477
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
14 changes: 4 additions & 10 deletions internal/cli/cmd/cluster/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/apecloud/kubeblocks/internal/cli/printer"
"github.com/apecloud/kubeblocks/internal/cli/types"
"github.com/apecloud/kubeblocks/internal/cli/util"
"github.com/apecloud/kubeblocks/internal/dataprotection/utils/boolptr"
)

var (
Expand Down Expand Up @@ -255,10 +256,6 @@ func showDataProtection(backupPolicies []dpv1alpha1.BackupPolicy, backupSchedule
tbl := newTbl(out, "\nData Protection:", "BACKUP-REPO", "AUTO-BACKUP", "BACKUP-SCHEDULE", "BACKUP-METHOD", "BACKUP-RETENTION")
for _, schedule := range backupSchedules {
backupRepo := defaultBackupRepo
backupMethod := printer.NoneString
backupSchedule := printer.NoneString
backupRetention := printer.NoneString
scheduleEnable := "Disabled"
for _, policy := range backupPolicies {
if policy.Name != schedule.Spec.BackupPolicyName {
continue
Expand All @@ -268,14 +265,11 @@ func showDataProtection(backupPolicies []dpv1alpha1.BackupPolicy, backupSchedule
}
}
for _, schedulePolicy := range schedule.Spec.Schedules {
if schedulePolicy.Enabled != nil && *schedulePolicy.Enabled == false {
if !boolptr.IsSetToTrue(schedulePolicy.Enabled) {
continue
}
scheduleEnable = "Enabled"
backupMethod = schedulePolicy.BackupMethod
backupSchedule = schedulePolicy.CronExpression
backupRetention = schedulePolicy.RetentionPeriod.String()
tbl.AddRow(backupRepo, scheduleEnable, backupSchedule, backupMethod, backupRetention)

tbl.AddRow(backupRepo, "Enabled", schedulePolicy.CronExpression, schedulePolicy.BackupMethod, schedulePolicy.RetentionPeriod.String())
}
}
tbl.Print()
Expand Down
27 changes: 4 additions & 23 deletions internal/cli/cmd/cluster/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import (
"bytes"
"net/http"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down Expand Up @@ -118,29 +116,12 @@ var _ = Describe("Expose", func() {
fakeBackupPolicies := []dpv1alpha1.BackupPolicy{
*testing.FakeBackupPolicy("backup-policy-test", "test-cluster"),
}
fakeBackups := []dpv1alpha1.Backup{
*testing.FakeBackup("backup-test"),
*testing.FakeBackup("backup-test2"),
fakeBackupSchedules := []dpv1alpha1.BackupSchedule{
*testing.FakeBackupSchedule("backup-schedule-test", "backup-policy-test"),
}
now := metav1.Now()
fakeBackups[0].Status = dpv1alpha1.BackupStatus{
Phase: dpv1alpha1.BackupPhaseCompleted,
TimeRange: &dpv1alpha1.BackupTimeRange{
Start: &now,
End: &now,
},
}
after := metav1.Time{Time: now.Add(time.Hour)}
fakeBackups[1].Status = dpv1alpha1.BackupStatus{
Phase: dpv1alpha1.BackupPhaseCompleted,
TimeRange: &dpv1alpha1.BackupTimeRange{
Start: &now,
End: &after,
},
}
showDataProtection(fakeBackupPolicies, fakeBackups, out)
strs := strings.Split(out.String(), "\n")

showDataProtection(fakeBackupPolicies, fakeBackupSchedules, "test-repository", out)
strs := strings.Split(out.String(), "\n")
Expect(strs).ShouldNot(BeEmpty())
})
})
31 changes: 31 additions & 0 deletions internal/cli/testing/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,37 @@ func FakeBackup(backupName string) *dpv1alpha1.Backup {
return backup
}

func FakeBackupSchedule(backupScheduleName, backupPolicyName string) *dpv1alpha1.BackupSchedule {
backupSchedule := &dpv1alpha1.BackupSchedule{
TypeMeta: metav1.TypeMeta{
APIVersion: fmt.Sprintf("%s/%s", types.DPAPIGroup, types.DPAPIVersion),
Kind: types.KindBackupSchedule,
},
ObjectMeta: metav1.ObjectMeta{
Name: backupScheduleName,
Namespace: Namespace,
Labels: map[string]string{
constant.AppInstanceLabelKey: ClusterName,
},
},
Spec: dpv1alpha1.BackupScheduleSpec{
BackupPolicyName: backupPolicyName,
Schedules: []dpv1alpha1.SchedulePolicy{
{
Enabled: boolptr.True(),
CronExpression: "0 0 * * *",
BackupMethod: BackupMethodName,
RetentionPeriod: dpv1alpha1.RetentionPeriod("1d"),
},
},
},
Status: dpv1alpha1.BackupScheduleStatus{
Phase: dpv1alpha1.BackupSchedulePhaseAvailable,
},
}
return backupSchedule
}

func FakeBackupWithCluster(cluster *appsv1alpha1.Cluster, backupName string) *dpv1alpha1.Backup {
backup := &dpv1alpha1.Backup{
TypeMeta: metav1.TypeMeta{
Expand Down
1 change: 1 addition & 0 deletions internal/cli/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const (
KindRestore = "Restore"
KindBackupPolicy = "BackupPolicy"
KindOps = "OpsRequest"
KindBackupSchedule = "BackupSchedule"
)

// K8S rbac API group
Expand Down

0 comments on commit 0cc9477

Please sign in to comment.