Files
velero/pkg/builder/pod_volume_backup_builder.go
KubeKween 6b66a49a21 Unit tests for restic restore (#1747)
* Add unit tests for PVB restore functionality

Signed-off-by: Carlisia <carlisiac@vmware.com>

* Add tests for restore action

Signed-off-by: Carlisia <carlisiac@vmware.com>

* TestRestoreWithRestic wip

Signed-off-by: Carlisia <carlisiac@vmware.com>

* Fix build

Signed-off-by: Carlisia <carlisiac@vmware.com>

* Mockery

Signed-off-by: Carlisia <carlisiac@vmware.com>

* Cleanup mocks

Signed-off-by: Carlisia <carlisiac@vmware.com>

* Remove unused mock

Signed-off-by: Carlisia <carlisiac@vmware.com>

* Use consistent pattern for test building

Signed-off-by: Carlisia <carlisia@vmware.com>

* Test cleanup

Signed-off-by: Carlisia <carlisia@vmware.com>

* Better godoc

Signed-off-by: Carlisia <carlisia@vmware.com>

* Improve test cases

Signed-off-by: Carlisia <carlisia@vmware.com>

* Fix build

Signed-off-by: Carlisia <carlisia@vmware.com>

* Minor test cleanup

Signed-off-by: Carlisia <carlisia@vmware.com>

* New pvb test input names

Signed-off-by: Carlisia <carlisia@vmware.com>
2019-08-27 15:49:23 -07:00

83 lines
2.4 KiB
Go

/*
Copyright 2019 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package builder
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
)
// PodVolumeBackupBuilder builds PodVolumeBackup objects
type PodVolumeBackupBuilder struct {
object *velerov1api.PodVolumeBackup
}
// ForPodVolumeBackup is the constructor for a PodVolumeBackupBuilder.
func ForPodVolumeBackup(ns, name string) *PodVolumeBackupBuilder {
return &PodVolumeBackupBuilder{
object: &velerov1api.PodVolumeBackup{
TypeMeta: metav1.TypeMeta{
APIVersion: velerov1api.SchemeGroupVersion.String(),
Kind: "PodVolumeBackup",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: name,
},
},
}
}
// Result returns the built PodVolumeBackup.
func (b *PodVolumeBackupBuilder) Result() *velerov1api.PodVolumeBackup {
return b.object
}
// ObjectMeta applies functional options to the PodVolumeBackup's ObjectMeta.
func (b *PodVolumeBackupBuilder) ObjectMeta(opts ...ObjectMetaOpt) *PodVolumeBackupBuilder {
for _, opt := range opts {
opt(b.object)
}
return b
}
// Phase sets the PodVolumeBackup's phase.
func (b *PodVolumeBackupBuilder) Phase(phase velerov1api.PodVolumeBackupPhase) *PodVolumeBackupBuilder {
b.object.Status.Phase = phase
return b
}
// SnapshotID sets the PodVolumeBackup's snapshot ID.
func (b *PodVolumeBackupBuilder) SnapshotID(snapshotID string) *PodVolumeBackupBuilder {
b.object.Status.SnapshotID = snapshotID
return b
}
// PodName sets the name of the pod associated with this PodVolumeBackup.
func (b *PodVolumeBackupBuilder) PodName(name string) *PodVolumeBackupBuilder {
b.object.Spec.Pod.Name = name
return b
}
// Volume sets the name of the volume associated with this PodVolumeBackup.
func (b *PodVolumeBackupBuilder) Volume(volume string) *PodVolumeBackupBuilder {
b.object.Spec.Volume = volume
return b
}