mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-19 21:56:12 +00:00
Add more unit test cases for cmd/util/output
Signed-off-by: Daniel Jiang <jiangd@vmware.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
)
|
||||
|
||||
// DeleteBackupRequestBuilder builds DeleteBackupRequest objects
|
||||
type DeleteBackupRequestBuilder struct {
|
||||
object *velerov1api.DeleteBackupRequest
|
||||
}
|
||||
|
||||
// ForDeleteBackupRequest is the constructor for a DeleteBackupRequestBuilder.
|
||||
func ForDeleteBackupRequest(ns, name string) *DeleteBackupRequestBuilder {
|
||||
return &DeleteBackupRequestBuilder{
|
||||
object: &velerov1api.DeleteBackupRequest{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: velerov1api.SchemeGroupVersion.String(),
|
||||
Kind: "DeleteBackupRequest",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: ns,
|
||||
Name: name,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Result returns the built DeleteBackupRequest.
|
||||
func (b *DeleteBackupRequestBuilder) Result() *velerov1api.DeleteBackupRequest {
|
||||
return b.object
|
||||
}
|
||||
|
||||
// ObjectMeta applies functional options to the DeleteBackupRequest's ObjectMeta.
|
||||
func (b *DeleteBackupRequestBuilder) ObjectMeta(opts ...ObjectMetaOpt) *DeleteBackupRequestBuilder {
|
||||
for _, opt := range opts {
|
||||
opt(b.object)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// BackupName sets the DeleteBackupRequest's backup name.
|
||||
func (b *DeleteBackupRequestBuilder) BackupName(name string) *DeleteBackupRequestBuilder {
|
||||
b.object.Spec.BackupName = name
|
||||
return b
|
||||
}
|
||||
|
||||
// Phase sets the DeleteBackupRequest's phase.
|
||||
func (b *DeleteBackupRequestBuilder) Phase(phase velerov1api.DeleteBackupRequestPhase) *DeleteBackupRequestBuilder {
|
||||
b.object.Status.Phase = phase
|
||||
return b
|
||||
}
|
||||
|
||||
// Errors sets the DeleteBackupRequest's errors.
|
||||
func (b *DeleteBackupRequestBuilder) Errors(errors ...string) *DeleteBackupRequestBuilder {
|
||||
b.object.Status.Errors = errors
|
||||
return b
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
"github.com/vmware-tanzu/velero/pkg/itemoperation"
|
||||
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// OperationStatusBuilder builds OperationStatus objects
|
||||
type OperationStatusBuilder struct {
|
||||
object *itemoperation.OperationStatus
|
||||
}
|
||||
|
||||
// ForOperationStatus is the constructor for a OperationStatusBuilder.
|
||||
func ForOperationStatus() *OperationStatusBuilder {
|
||||
return &OperationStatusBuilder{
|
||||
object: &itemoperation.OperationStatus{},
|
||||
}
|
||||
}
|
||||
|
||||
// Result returns the built OperationStatus.
|
||||
func (osb *OperationStatusBuilder) Result() *itemoperation.OperationStatus {
|
||||
return osb.object
|
||||
}
|
||||
|
||||
// Phase sets the OperationStatus's phase.
|
||||
func (osb *OperationStatusBuilder) Phase(phase itemoperation.OperationPhase) *OperationStatusBuilder {
|
||||
osb.object.Phase = phase
|
||||
return osb
|
||||
}
|
||||
|
||||
// Error sets the OperationStatus's error.
|
||||
func (osb *OperationStatusBuilder) Error(err string) *OperationStatusBuilder {
|
||||
osb.object.Error = err
|
||||
return osb
|
||||
}
|
||||
|
||||
// Progress sets the OperationStatus's progress.
|
||||
func (osb *OperationStatusBuilder) Progress(nComplete int64, nTotal int64, operationUnits string) *OperationStatusBuilder {
|
||||
osb.object.NCompleted = nComplete
|
||||
osb.object.NTotal = nTotal
|
||||
osb.object.OperationUnits = operationUnits
|
||||
return osb
|
||||
}
|
||||
|
||||
// Description sets the OperationStatus's description.
|
||||
func (osb *OperationStatusBuilder) Description(desc string) *OperationStatusBuilder {
|
||||
osb.object.Description = desc
|
||||
return osb
|
||||
}
|
||||
|
||||
// Created sets the OperationStatus's creation timestamp.
|
||||
func (osb *OperationStatusBuilder) Created(t time.Time) *OperationStatusBuilder {
|
||||
osb.object.Created = &metav1.Time{Time: t}
|
||||
return osb
|
||||
}
|
||||
|
||||
// Updated sets the OperationStatus's last update timestamp.
|
||||
func (osb *OperationStatusBuilder) Updated(t time.Time) *OperationStatusBuilder {
|
||||
osb.object.Updated = &metav1.Time{Time: t}
|
||||
return osb
|
||||
}
|
||||
|
||||
// Started sets the OperationStatus's start timestamp.
|
||||
func (osb *OperationStatusBuilder) Started(t time.Time) *OperationStatusBuilder {
|
||||
osb.object.Started = &metav1.Time{Time: t}
|
||||
return osb
|
||||
}
|
||||
|
||||
// BackupOperationBuilder builds BackupOperation objects
|
||||
type BackupOperationBuilder struct {
|
||||
object *itemoperation.BackupOperation
|
||||
}
|
||||
|
||||
// ForBackupOperation is the constructor for a BackupOperationBuilder.
|
||||
func ForBackupOperation() *BackupOperationBuilder {
|
||||
return &BackupOperationBuilder{
|
||||
object: &itemoperation.BackupOperation{},
|
||||
}
|
||||
}
|
||||
|
||||
// Result returns the built BackupOperation.
|
||||
func (bb *BackupOperationBuilder) Result() *itemoperation.BackupOperation {
|
||||
return bb.object
|
||||
}
|
||||
|
||||
// BackupName sets the BackupOperation's backup name.
|
||||
func (bb *BackupOperationBuilder) BackupName(name string) *BackupOperationBuilder {
|
||||
bb.object.Spec.BackupName = name
|
||||
return bb
|
||||
}
|
||||
|
||||
// OperationID sets the BackupOperation's operation ID.
|
||||
func (bb *BackupOperationBuilder) OperationID(id string) *BackupOperationBuilder {
|
||||
bb.object.Spec.OperationID = id
|
||||
return bb
|
||||
}
|
||||
|
||||
// Status sets the BackupOperation's status.
|
||||
func (bb *BackupOperationBuilder) Status(status itemoperation.OperationStatus) *BackupOperationBuilder {
|
||||
bb.object.Status = status
|
||||
return bb
|
||||
}
|
||||
|
||||
// ResourceIdentifier sets the BackupOperation's resource identifier.
|
||||
func (bb *BackupOperationBuilder) ResourceIdentifier(group, resource, ns, name string) *BackupOperationBuilder {
|
||||
bb.object.Spec.ResourceIdentifier = velero.ResourceIdentifier{
|
||||
GroupResource: schema.GroupResource{
|
||||
Group: group,
|
||||
Resource: resource,
|
||||
},
|
||||
Namespace: ns,
|
||||
Name: name,
|
||||
}
|
||||
return bb
|
||||
}
|
||||
|
||||
// BackupItemAction sets the BackupOperation's backup item action.
|
||||
func (bb *BackupOperationBuilder) BackupItemAction(bia string) *BackupOperationBuilder {
|
||||
bb.object.Spec.BackupItemAction = bia
|
||||
return bb
|
||||
}
|
||||
|
||||
// PostOperationItem adds a post-operation item to the BackupOperation's list of post-operation items.
|
||||
func (bb *BackupOperationBuilder) PostOperationItem(group, resource, ns, name string) *BackupOperationBuilder {
|
||||
bb.object.Spec.PostOperationItems = append(bb.object.Spec.PostOperationItems, velero.ResourceIdentifier{
|
||||
GroupResource: schema.GroupResource{
|
||||
Group: group,
|
||||
Resource: resource,
|
||||
},
|
||||
Namespace: ns,
|
||||
Name: name,
|
||||
})
|
||||
return bb
|
||||
}
|
||||
|
||||
// RestoreOperationBuilder builds RestoreOperation objects
|
||||
type RestoreOperationBuilder struct {
|
||||
object *itemoperation.RestoreOperation
|
||||
}
|
||||
|
||||
// ForRestoreOperation is the constructor for a RestoreOperationBuilder.
|
||||
func ForRestoreOperation() *RestoreOperationBuilder {
|
||||
return &RestoreOperationBuilder{
|
||||
object: &itemoperation.RestoreOperation{},
|
||||
}
|
||||
}
|
||||
|
||||
// Result returns the built RestoreOperation.
|
||||
func (rb *RestoreOperationBuilder) Result() *itemoperation.RestoreOperation {
|
||||
return rb.object
|
||||
}
|
||||
|
||||
// RestoreName sets the RestoreOperation's restore name.
|
||||
func (rb *RestoreOperationBuilder) RestoreName(name string) *RestoreOperationBuilder {
|
||||
rb.object.Spec.RestoreName = name
|
||||
return rb
|
||||
}
|
||||
|
||||
// OperationID sets the RestoreOperation's operation ID.
|
||||
func (rb *RestoreOperationBuilder) OperationID(id string) *RestoreOperationBuilder {
|
||||
rb.object.Spec.OperationID = id
|
||||
return rb
|
||||
}
|
||||
|
||||
// RestoreItemAction sets the RestoreOperation's restore item action.
|
||||
func (rb *RestoreOperationBuilder) RestoreItemAction(ria string) *RestoreOperationBuilder {
|
||||
rb.object.Spec.RestoreItemAction = ria
|
||||
return rb
|
||||
}
|
||||
|
||||
// Status sets the RestoreOperation's status.
|
||||
func (rb *RestoreOperationBuilder) Status(status itemoperation.OperationStatus) *RestoreOperationBuilder {
|
||||
rb.object.Status = status
|
||||
return rb
|
||||
}
|
||||
|
||||
// ResourceIdentifier sets the RestoreOperation's resource identifier.
|
||||
func (rb *RestoreOperationBuilder) ResourceIdentifier(group, resource, ns, name string) *RestoreOperationBuilder {
|
||||
rb.object.Spec.ResourceIdentifier = velero.ResourceIdentifier{
|
||||
GroupResource: schema.GroupResource{
|
||||
Group: group,
|
||||
Resource: resource,
|
||||
},
|
||||
Namespace: ns,
|
||||
Name: name,
|
||||
}
|
||||
return rb
|
||||
}
|
||||
@@ -153,3 +153,10 @@ func WithManagedFields(val []metav1.ManagedFieldsEntry) func(obj metav1.Object)
|
||||
obj.SetManagedFields(val)
|
||||
}
|
||||
}
|
||||
|
||||
// WithCreationTimestamp is a functional option that applies the specified creationTimestamp
|
||||
func WithCreationTimestamp(t time.Time) func(obj metav1.Object) {
|
||||
return func(obj metav1.Object) {
|
||||
obj.SetCreationTimestamp(metav1.Time{Time: t})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ func (b *PodVolumeBackupBuilder) ObjectMeta(opts ...ObjectMetaOpt) *PodVolumeBac
|
||||
for _, opt := range opts {
|
||||
opt(b.object)
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
)
|
||||
|
||||
// PodVolumeRestoreBuilder builds PodVolumeRestore objects.
|
||||
type PodVolumeRestoreBuilder struct {
|
||||
object *velerov1api.PodVolumeRestore
|
||||
}
|
||||
|
||||
// ForPodVolumeRestore is the constructor for a PodVolumeRestoreBuilder.
|
||||
func ForPodVolumeRestore(ns, name string) *PodVolumeRestoreBuilder {
|
||||
return &PodVolumeRestoreBuilder{
|
||||
object: &velerov1api.PodVolumeRestore{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: velerov1api.SchemeGroupVersion.String(),
|
||||
Kind: "PodVolumeRestore",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: ns,
|
||||
Name: name,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Result returns the built PodVolumeRestore.
|
||||
func (b *PodVolumeRestoreBuilder) Result() *velerov1api.PodVolumeRestore {
|
||||
return b.object
|
||||
}
|
||||
|
||||
// ObjectMeta applies functional options to the PodVolumeRestore's ObjectMeta.
|
||||
func (b *PodVolumeRestoreBuilder) ObjectMeta(opts ...ObjectMetaOpt) *PodVolumeRestoreBuilder {
|
||||
for _, opt := range opts {
|
||||
opt(b.object)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// Phase sets the PodVolumeRestore's phase.
|
||||
func (b *PodVolumeRestoreBuilder) Phase(phase velerov1api.PodVolumeRestorePhase) *PodVolumeRestoreBuilder {
|
||||
b.object.Status.Phase = phase
|
||||
return b
|
||||
}
|
||||
|
||||
// BackupStorageLocation sets the PodVolumeRestore's backup storage location.
|
||||
func (b *PodVolumeRestoreBuilder) BackupStorageLocation(name string) *PodVolumeRestoreBuilder {
|
||||
b.object.Spec.BackupStorageLocation = name
|
||||
return b
|
||||
}
|
||||
|
||||
// SnapshotID sets the PodVolumeRestore's snapshot ID.
|
||||
func (b *PodVolumeRestoreBuilder) SnapshotID(snapshotID string) *PodVolumeRestoreBuilder {
|
||||
b.object.Spec.SnapshotID = snapshotID
|
||||
return b
|
||||
}
|
||||
|
||||
// PodName sets the name of the pod associated with this PodVolumeRestore.
|
||||
func (b *PodVolumeRestoreBuilder) PodName(name string) *PodVolumeRestoreBuilder {
|
||||
b.object.Spec.Pod.Name = name
|
||||
return b
|
||||
}
|
||||
|
||||
// PodNamespace sets the name of the pod associated with this PodVolumeRestore.
|
||||
func (b *PodVolumeRestoreBuilder) PodNamespace(ns string) *PodVolumeRestoreBuilder {
|
||||
b.object.Spec.Pod.Namespace = ns
|
||||
return b
|
||||
}
|
||||
|
||||
// Volume sets the name of the volume associated with this PodVolumeRestore.
|
||||
func (b *PodVolumeRestoreBuilder) Volume(volume string) *PodVolumeRestoreBuilder {
|
||||
b.object.Spec.Volume = volume
|
||||
return b
|
||||
}
|
||||
|
||||
// UploaderType sets the type of uploader to use for this PodVolumeRestore.
|
||||
func (b *PodVolumeRestoreBuilder) UploaderType(uploaderType string) *PodVolumeRestoreBuilder {
|
||||
b.object.Spec.UploaderType = uploaderType
|
||||
return b
|
||||
}
|
||||
Reference in New Issue
Block a user