Add UT for pkg/cmd/cli/backup (#6400)

Signed-off-by: danfengl <danfengl@vmware.com>
This commit is contained in:
danfengliu
2023-06-21 11:10:13 +08:00
committed by GitHub
parent 6f3adcf728
commit ef443fece0
33 changed files with 2984 additions and 32 deletions

View File

@@ -1,4 +1,4 @@
// Code generated by mockery v2.28.1. DO NOT EDIT.
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
@@ -186,13 +186,12 @@ func (_m *Factory) SetClientQPS(_a0 float32) {
_m.Called(_a0)
}
type mockConstructorTestingTNewFactory interface {
// NewFactory creates a new instance of Factory. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewFactory(t interface {
mock.TestingT
Cleanup(func())
}
// NewFactory creates a new instance of Factory. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func NewFactory(t mockConstructorTestingTNewFactory) *Factory {
}) *Factory {
mock := &Factory{}
mock.Mock.Test(t)

View File

@@ -0,0 +1,34 @@
/*
Copyright 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 backup
import (
"testing"
"github.com/stretchr/testify/assert"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
)
func TestNewBackupCommand(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
// create command
cmd := NewCommand(f)
assert.Equal(t, "Work with backups", cmd.Short)
}

View File

@@ -139,16 +139,16 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
f := flags.VarPF(&o.SnapshotVolumes, "snapshot-volumes", "", "Take snapshots of PersistentVolumes as part of the backup. If the parameter is not set, it is treated as setting to 'true'.")
// this allows the user to just specify "--snapshot-volumes" as shorthand for "--snapshot-volumes=true"
// like a normal bool flag
f.NoOptDefVal = "true"
f.NoOptDefVal = cmd.TRUE
f = flags.VarPF(&o.SnapshotMoveData, "snapshot-move-data", "", "Specify whether snapshot data should be moved")
f.NoOptDefVal = "true"
f.NoOptDefVal = cmd.TRUE
f = flags.VarPF(&o.IncludeClusterResources, "include-cluster-resources", "", "Include cluster-scoped resources in the backup. Cannot work with include-cluster-scoped-resources, exclude-cluster-scoped-resources, include-namespace-scoped-resources and exclude-namespace-scoped-resources.")
f.NoOptDefVal = "true"
f.NoOptDefVal = cmd.TRUE
f = flags.VarPF(&o.DefaultVolumesToFsBackup, "default-volumes-to-fs-backup", "", "Use pod volume file system backup by default for volumes")
f.NoOptDefVal = "true"
f.NoOptDefVal = cmd.TRUE
flags.StringVar(&o.ResPoliciesConfigmap, "resource-policies-configmap", "", "Reference to the resource policies configmap that backup using")
flags.StringVar(&o.DataMover, "data-mover", "", "Specify the data mover to be used by the backup. If the parameter is not set or set as 'velero', the built-in data mover will be used")

View File

@@ -18,18 +18,30 @@ package backup
import (
"context"
"fmt"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
flag "github.com/spf13/pflag"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/builder"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake"
)
const testNamespace = "velero"
clientfake "sigs.k8s.io/controller-runtime/pkg/client/fake"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
velerov1mocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1/mocks"
"github.com/vmware-tanzu/velero/pkg/test"
)
func TestCreateOptions_BuildBackup(t *testing.T) {
o := NewCreateOptions()
@@ -40,7 +52,7 @@ func TestCreateOptions_BuildBackup(t *testing.T) {
o.ItemOperationTimeout = 20 * time.Minute
assert.NoError(t, err)
backup, err := o.BuildBackup(testNamespace)
backup, err := o.BuildBackup(cmdtest.VeleroNameSpace)
assert.NoError(t, err)
assert.Equal(t, velerov1api.BackupSpec{
@@ -68,16 +80,16 @@ func TestCreateOptions_BuildBackupFromSchedule(t *testing.T) {
o.client = fake.NewSimpleClientset()
t.Run("inexistent schedule", func(t *testing.T) {
_, err := o.BuildBackup(testNamespace)
_, err := o.BuildBackup(cmdtest.VeleroNameSpace)
assert.Error(t, err)
})
expectedBackupSpec := builder.ForBackup("test", testNamespace).IncludedNamespaces("test").Result().Spec
schedule := builder.ForSchedule(testNamespace, "test").Template(expectedBackupSpec).ObjectMeta(builder.WithLabels("velero.io/test", "true"), builder.WithAnnotations("velero.io/test", "true")).Result()
o.client.VeleroV1().Schedules(testNamespace).Create(context.TODO(), schedule, metav1.CreateOptions{})
expectedBackupSpec := builder.ForBackup("test", cmdtest.VeleroNameSpace).IncludedNamespaces("test").Result().Spec
schedule := builder.ForSchedule(cmdtest.VeleroNameSpace, "test").Template(expectedBackupSpec).ObjectMeta(builder.WithLabels("velero.io/test", "true"), builder.WithAnnotations("velero.io/test", "true")).Result()
o.client.VeleroV1().Schedules(cmdtest.VeleroNameSpace).Create(context.TODO(), schedule, metav1.CreateOptions{})
t.Run("existing schedule", func(t *testing.T) {
backup, err := o.BuildBackup(testNamespace)
backup, err := o.BuildBackup(cmdtest.VeleroNameSpace)
assert.NoError(t, err)
assert.Equal(t, expectedBackupSpec, backup.Spec)
@@ -92,7 +104,7 @@ func TestCreateOptions_BuildBackupFromSchedule(t *testing.T) {
t.Run("command line labels take precedence over schedule labels", func(t *testing.T) {
o.Labels.Set("velero.io/test=yes,custom-label=true")
backup, err := o.BuildBackup(testNamespace)
backup, err := o.BuildBackup(cmdtest.VeleroNameSpace)
assert.NoError(t, err)
assert.Equal(t, expectedBackupSpec, backup.Spec)
@@ -127,3 +139,235 @@ func TestCreateOptions_OrderedResources(t *testing.T) {
assert.Equal(t, orderedResources, expectedMixedResources)
}
func TestCreateCommand(t *testing.T) {
name := "nameToBeCreated"
args := []string{name}
t.Run("create a backup create command with full options except fromSchedule and wait, then run by create option", func(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
// create command
cmd := NewCreateCommand(f, "")
assert.Equal(t, "Create a backup", cmd.Short)
includeNamespaces := "app1,app2"
excludeNamespaces := "pod1,pod2,pod3"
includeResources := "sc,sts"
excludeResources := "job"
includeClusterScopedResources := "pv,ComponentStatus"
excludeClusterScopedResources := "MutatingWebhookConfiguration,APIService"
includeNamespaceScopedResources := "Endpoints,Event,PodTemplate"
excludeNamespaceScopedResources := "Secret,MultiClusterIngress"
labels := "c=foo,b=woo"
storageLocation := "bsl-name-1"
snapshotLocations := "region=minio"
selector := "a=pod"
orderedResources := "pod=pod1,pod2,pod3"
csiSnapshotTimeout := "8m30s"
itemOperationTimeout := "99h1m6s"
snapshotVolumes := "false"
snapshotMoveData := "true"
includeClusterResources := "true"
defaultVolumesToFsBackup := "true"
resPoliciesConfigmap := "cm-name-2"
dataMover := "velero"
flags := new(flag.FlagSet)
o := NewCreateOptions()
o.BindFlags(flags)
o.BindWait(flags)
o.BindFromSchedule(flags)
flags.Parse([]string{"--include-namespaces", includeNamespaces})
flags.Parse([]string{"--exclude-namespaces", excludeNamespaces})
flags.Parse([]string{"--include-resources", includeResources})
flags.Parse([]string{"--exclude-resources", excludeResources})
flags.Parse([]string{"--include-cluster-scoped-resources", includeClusterScopedResources})
flags.Parse([]string{"--exclude-cluster-scoped-resources", excludeClusterScopedResources})
flags.Parse([]string{"--include-namespace-scoped-resources", includeNamespaceScopedResources})
flags.Parse([]string{"--exclude-namespace-scoped-resources", excludeNamespaceScopedResources})
flags.Parse([]string{"--labels", labels})
flags.Parse([]string{"--storage-location", storageLocation})
flags.Parse([]string{"--volume-snapshot-locations", snapshotLocations})
flags.Parse([]string{"--selector", selector})
flags.Parse([]string{"--ordered-resources", orderedResources})
flags.Parse([]string{"--csi-snapshot-timeout", csiSnapshotTimeout})
flags.Parse([]string{"--item-operation-timeout", itemOperationTimeout})
flags.Parse([]string{fmt.Sprintf("--snapshot-volumes=%s", snapshotVolumes)})
flags.Parse([]string{fmt.Sprintf("--snapshot-move-data=%s", snapshotMoveData)})
flags.Parse([]string{"--include-cluster-resources", includeClusterResources})
flags.Parse([]string{"--default-volumes-to-fs-backup", defaultVolumesToFsBackup})
flags.Parse([]string{"--resource-policies-configmap", resPoliciesConfigmap})
flags.Parse([]string{"--data-mover", dataMover})
//flags.Parse([]string{"--wait"})
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
bk := &velerov1api.Backup{}
backups.On("Create", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(nil, nil)
//Complete
e := o.Complete(args, f)
assert.NoError(t, e)
//Validate
e = o.Validate(cmd, args, f)
assert.Contains(t, e.Error(), "include-resources, exclude-resources and include-cluster-resources are old filter parameters")
assert.Contains(t, e.Error(), "include-cluster-scoped-resources, exclude-cluster-scoped-resources, include-namespace-scoped-resources and exclude-namespace-scoped-resources are new filter parameters.\nThey cannot be used together")
//cmd
e = o.Run(cmd, f)
assert.NoError(t, e)
//Execute
cmd.SetArgs([]string{"bk-name-exe"})
e = cmd.Execute()
assert.NoError(t, e)
// verify all options are set as expected
assert.Equal(t, name, o.Name)
assert.Equal(t, includeNamespaces, o.IncludeNamespaces.String())
assert.Equal(t, excludeNamespaces, o.ExcludeNamespaces.String())
assert.Equal(t, includeResources, o.IncludeResources.String())
assert.Equal(t, excludeResources, o.ExcludeResources.String())
assert.Equal(t, includeClusterScopedResources, o.IncludeClusterScopedResources.String())
assert.Equal(t, excludeClusterScopedResources, o.ExcludeClusterScopedResources.String())
assert.Equal(t, includeNamespaceScopedResources, o.IncludeNamespaceScopedResources.String())
assert.Equal(t, excludeNamespaceScopedResources, o.ExcludeNamespaceScopedResources.String())
assert.Equal(t, true, test.CompareSlice(strings.Split(labels, ","), strings.Split(o.Labels.String(), ",")))
assert.Equal(t, storageLocation, o.StorageLocation)
assert.Equal(t, snapshotLocations, strings.Split(o.SnapshotLocations[0], ",")[0])
assert.Equal(t, selector, o.Selector.String())
assert.Equal(t, orderedResources, o.OrderedResources)
assert.Equal(t, csiSnapshotTimeout, o.CSISnapshotTimeout.String())
assert.Equal(t, itemOperationTimeout, o.ItemOperationTimeout.String())
assert.Equal(t, snapshotVolumes, o.SnapshotVolumes.String())
assert.Equal(t, snapshotMoveData, o.SnapshotMoveData.String())
assert.Equal(t, includeClusterResources, o.IncludeClusterResources.String())
assert.Equal(t, defaultVolumesToFsBackup, o.DefaultVolumesToFsBackup.String())
assert.Equal(t, resPoliciesConfigmap, o.ResPoliciesConfigmap)
assert.Equal(t, dataMover, o.DataMover)
//assert.Equal(t, true, o.Wait)
// verify oldAndNewFilterParametersUsedTogether
mix := o.oldAndNewFilterParametersUsedTogether()
assert.Equal(t, true, mix)
})
t.Run("create a backup create command with specific storage-location setting", func(t *testing.T) {
bsl := "bsl-1"
// create a factory
f := &factorymocks.Factory{}
cmd := NewCreateCommand(f, "")
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
kbclient := clientfake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
bk := &velerov1api.Backup{}
backups.On("Create", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
flags := new(flag.FlagSet)
o := NewCreateOptions()
o.BindFlags(flags)
o.BindWait(flags)
o.BindFromSchedule(flags)
flags.Parse([]string{"--include-namespaces", "ns-1"})
flags.Parse([]string{"--storage-location", bsl})
// Complete
e := o.Complete(args, f)
assert.NoError(t, e)
// Validate
e = o.Validate(cmd, args, f)
assert.Contains(t, e.Error(), fmt.Sprintf("backupstoragelocations.velero.io \"%s\" not found", bsl))
})
t.Run("create a backup create command with specific volume-snapshot-locations setting", func(t *testing.T) {
vslName := "vsl-1"
// create a factory
f := &factorymocks.Factory{}
cmd := NewCreateCommand(f, "")
vsls := &velerov1mocks.VolumeSnapshotLocationInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
kbclient := clientfake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
vsl := &velerov1api.VolumeSnapshotLocation{}
vsls.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(vsl, nil)
veleroV1.On("VolumeSnapshotLocations", mock.Anything).Return(vsls, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
flags := new(flag.FlagSet)
o := NewCreateOptions()
o.BindFlags(flags)
o.BindWait(flags)
o.BindFromSchedule(flags)
flags.Parse([]string{"--include-namespaces", "ns-1"})
flags.Parse([]string{"--volume-snapshot-locations", vslName})
// Complete
e := o.Complete(args, f)
assert.NoError(t, e)
// Validate
e = o.Validate(cmd, args, f)
assert.NoError(t, e)
})
t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) {
f := &factorymocks.Factory{}
c := NewCreateCommand(f, "")
assert.Equal(t, "Create a backup", c.Short)
flags := new(flag.FlagSet)
o := NewCreateOptions()
o.BindFlags(flags)
o.BindWait(flags)
o.BindFromSchedule(flags)
fromSchedule := "schedule-name-1"
flags.Parse([]string{"--from-schedule", fromSchedule})
backups := &velerov1mocks.BackupInterface{}
bk := &velerov1api.Backup{}
schedules := &velerov1mocks.ScheduleInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
kbclient := clientfake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
sd := &velerov1api.Schedule{}
backups.On("Create", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
schedules.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(sd, nil)
veleroV1.On("Schedules", mock.Anything).Return(schedules, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
e := o.Complete(args, f)
assert.NoError(t, e)
e = o.Run(c, f)
assert.NoError(t, e)
c.SetArgs([]string{"bk-1"})
e = c.Execute()
assert.NoError(t, e)
})
}

View File

@@ -0,0 +1,96 @@
/*
Copyright 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 backup
import (
"fmt"
"os"
"os/exec"
"testing"
flag "github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
"github.com/vmware-tanzu/velero/pkg/cmd/cli"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
velerov1mocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1/mocks"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
)
func TestDeleteCommand(t *testing.T) {
backupName := "backup-name-1"
// create a factory
f := &factorymocks.Factory{}
deleteBackupRequest := &velerov1mocks.DeleteBackupRequestInterface{}
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
bk := &velerov1api.Backup{}
dbr := &velerov1api.DeleteBackupRequest{}
backups.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
deleteBackupRequest.On("Create", mock.Anything, mock.Anything, mock.Anything).Return(dbr, nil)
veleroV1.On("DeleteBackupRequests", mock.Anything).Return(deleteBackupRequest, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
// create command
c := NewDeleteCommand(f, "velero backup delete")
c.SetArgs([]string{backupName})
assert.Equal(t, "Delete backups", c.Short)
o := cli.NewDeleteOptions("backup")
flags := new(flag.FlagSet)
o.BindFlags(flags)
flags.Parse([]string{"--confirm"})
args := []string{"bk1", "bk2"}
bk.Name = backupName
e := o.Complete(f, args)
assert.Equal(t, e, nil)
e = o.Validate(c, f, args)
assert.Equal(t, e, nil)
e = Run(o)
assert.Equal(t, e, nil)
e = c.Execute()
assert.Equal(t, e, nil)
if os.Getenv(cmdtest.CaptureFlag) == "1" {
return
}
cmd := exec.Command(os.Args[0], []string{"-test.run=TestDeleteCommand"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
stdout, _, err := veleroexec.RunCommand(cmd)
if err == nil {
assert.Contains(t, stdout, fmt.Sprintf("Request to delete backup \"%s\" submitted successfully.", backupName))
return
}
t.Fatalf("process ran with err %v, want backups by get()", err)
}

View File

@@ -0,0 +1,94 @@
/*
Copyright 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 backup
import (
"fmt"
"os"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"k8s.io/client-go/rest"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
"github.com/vmware-tanzu/velero/pkg/features"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
velerov1mocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1/mocks"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
)
func TestNewDescribeCommand(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
clientConfig := rest.Config{}
deleteBackupRequest := &velerov1mocks.DeleteBackupRequestInterface{}
bk := &velerov1api.Backup{}
bkList := &velerov1api.BackupList{}
deleteBackupRequestList := &velerov1api.DeleteBackupRequestList{}
podVolumeBackups := &velerov1mocks.PodVolumeBackupInterface{}
podVolumeBackupList := &velerov1api.PodVolumeBackupList{}
backupName := "bk-describe-1"
bk.Name = backupName
backups.On("List", mock.Anything, mock.Anything).Return(bkList, nil)
backups.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
deleteBackupRequest.On("List", mock.Anything, mock.Anything).Return(deleteBackupRequestList, nil)
veleroV1.On("DeleteBackupRequests", mock.Anything).Return(deleteBackupRequest, nil)
podVolumeBackups.On("List", mock.Anything, mock.Anything).Return(podVolumeBackupList, nil)
veleroV1.On("PodVolumeBackups", mock.Anything, mock.Anything).Return(podVolumeBackups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("ClientConfig").Return(&clientConfig, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(nil, nil)
// create command
c := NewDescribeCommand(f, "velero backup describe")
assert.Equal(t, "Describe backups", c.Short)
features.NewFeatureFlagSet("EnableCSI")
defer features.NewFeatureFlagSet()
c.SetArgs([]string{"bk1"})
e := c.Execute()
assert.NoError(t, e)
if os.Getenv(cmdtest.CaptureFlag) == "1" {
return
}
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewDescribeCommand"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
stdout, _, err := veleroexec.RunCommand(cmd)
if err == nil {
assert.Contains(t, stdout, "Velero-Native Snapshots: <none included>")
assert.Contains(t, stdout, fmt.Sprintf("Name: %s", backupName))
return
}
t.Fatalf("process ran with err %v, want backups by get()", err)
}

View File

@@ -0,0 +1,112 @@
/*
Copyright 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 backup
import (
"fmt"
"os"
"os/exec"
"strconv"
"testing"
flag "github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
velerov1mocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1/mocks"
)
func TestNewDownloadCommand(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
bk := &velerov1api.Backup{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
backups.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
// create command
c := NewDownloadCommand(f)
c.SetArgs([]string{"bk-to-be-download"})
assert.Equal(t, "Download all Kubernetes manifests for a backup", c.Short)
// create a DownloadOptions with full options set and then run this backup command
output := "path/to/download/bk.json"
force := true
timeout := "1m30s"
insecureSkipTlsVerify := false
cacert := "secret=YHJKKS"
flags := new(flag.FlagSet)
o := NewDownloadOptions()
o.BindFlags(flags)
flags.Parse([]string{"--output", output})
flags.Parse([]string{"--force"})
flags.Parse([]string{"--timeout", timeout})
flags.Parse([]string{fmt.Sprintf("--insecure-skip-tls-verify=%s", strconv.FormatBool(insecureSkipTlsVerify))})
flags.Parse([]string{"--cacert", cacert})
backupName := "backup-1"
args := []string{backupName, "arg2"}
e := o.Complete(args)
assert.NoError(t, e)
e = o.Validate(c, args, f)
assert.NoError(t, e)
// verify all options are set as expected
assert.Equal(t, output, o.Output)
assert.Equal(t, force, o.Force)
assert.Equal(t, timeout, o.Timeout.String())
assert.Equal(t, insecureSkipTlsVerify, o.InsecureSkipTLSVerify)
assert.Equal(t, cacert, o.caCertFile)
if os.Getenv(cmdtest.CaptureFlag) == "1" {
e = c.Execute()
defer os.Remove("bk-to-be-download-data.tar.gz")
assert.NoError(t, e)
return
}
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewDownloadCommand"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
_, stderr, err := veleroexec.RunCommand(cmd)
if err != nil {
assert.Contains(t, stderr, "download request download url timeout")
return
}
t.Fatalf("process ran with err %v, want backup delete successfully", err)
}

View File

@@ -0,0 +1,85 @@
/*
Copyright 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 backup
import (
"fmt"
"os"
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
velerov1mocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1/mocks"
)
func TestNewGetCommand(t *testing.T) {
args := []string{"b1", "b2", "b3"}
// create a factory
f := &factorymocks.Factory{}
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
bk := &velerov1api.Backup{}
bkList := &velerov1api.BackupList{}
backups.On("List", mock.Anything, mock.Anything).Return(bkList, nil)
backups.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
// create command
c := NewGetCommand(f, "velero backup get")
assert.Equal(t, "Get backups", c.Short)
c.SetArgs(args)
e := c.Execute()
assert.NoError(t, e)
if os.Getenv(cmdtest.CaptureFlag) == "1" {
return
}
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewGetCommand"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
stdout, _, err := veleroexec.RunCommand(cmd)
if err == nil {
output := strings.Split(stdout, "\n")
i := 0
for _, line := range output {
if strings.Contains(line, "New") {
i++
}
}
assert.Equal(t, len(args), i)
return
}
t.Fatalf("process ran with err %v, want backups by get()", err)
}

View File

@@ -0,0 +1,78 @@
/*
Copyright 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 backup
import (
"fmt"
"os"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
velerov1mocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1/mocks"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
)
func TestNewLogsCommand(t *testing.T) {
backupName := "bk-logs-1"
// create a factory
f := &factorymocks.Factory{}
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
bk := &velerov1api.Backup{}
bkList := &velerov1api.BackupList{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
backups.On("List", mock.Anything, mock.Anything).Return(bkList, nil)
backups.On("Get", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
c := NewLogsCommand(f)
assert.Equal(t, "Get backup logs", c.Short)
if os.Getenv(cmdtest.CaptureFlag) == "1" {
c.SetArgs([]string{backupName})
e := c.Execute()
assert.NoError(t, e)
return
}
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewLogsCommand"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
_, stderr, err := veleroexec.RunCommand(cmd)
if err != nil {
assert.Contains(t, stderr, fmt.Sprintf("Logs for backup \"%s\" are not available until it's finished processing", backupName))
return
}
t.Fatalf("process ran with err %v, want backup delete successfully", err)
}

View File

@@ -0,0 +1,34 @@
/*
Copyright 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 backuplocation
import (
"testing"
"github.com/stretchr/testify/assert"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
)
func TestNewCommand(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
// create command
c := NewCommand(f)
assert.Equal(t, "Work with backup storage locations", c.Short)
}

View File

@@ -17,12 +17,28 @@ limitations under the License.
package backuplocation
import (
"fmt"
"reflect"
"strings"
"testing"
"time"
flag "github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
veleroflag "github.com/vmware-tanzu/velero/pkg/cmd/util/flag"
"github.com/vmware-tanzu/velero/pkg/test"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
velerov1mocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1/mocks"
)
func TestBuildBackupStorageLocationSetsNamespace(t *testing.T) {
@@ -87,3 +103,99 @@ func TestBuildBackupStorageLocationSetsLabels(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, map[string]string{"key": "value"}, bsl.Labels)
}
func TestCreateCommand_Run(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
// create command
c := NewCreateCommand(f, "")
assert.Equal(t, "Create a backup storage location", c.Short)
// create a CreateOptions with full options set and then run this backup command
name := "bsl-name-to-be-created"
provider := "aws"
bucket := "velero123456"
credential := veleroflag.NewMap()
credential.Set("secret=a")
defaultBackupStorageLocation := true
prefix := "builds"
backupSyncPeriod := "1m30s"
validationFrequency := "128h1m6s"
bslConfig := veleroflag.NewMap()
bslConfigStr := "region=minio"
bslConfig.Set(bslConfigStr)
labels := "a=too,b=woo"
caCertFile := "bsl-name-1"
accessMode := "ReadWrite"
flags := new(flag.FlagSet)
o := NewCreateOptions()
o.BindFlags(flags)
flags.Parse([]string{"--provider", provider})
flags.Parse([]string{"--bucket", bucket})
flags.Parse([]string{"--credential", credential.String()})
flags.Parse([]string{"--default"})
flags.Parse([]string{"--prefix", prefix})
flags.Parse([]string{"--backup-sync-period", backupSyncPeriod})
flags.Parse([]string{"--validation-frequency", validationFrequency})
flags.Parse([]string{"--config", bslConfigStr})
flags.Parse([]string{"--labels", labels})
flags.Parse([]string{"--cacert", caCertFile})
flags.Parse([]string{"--access-mode", accessMode})
args := []string{name, "arg2"}
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
bk := &velerov1api.Backup{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
backups.On("Create", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
o.Complete(args, f)
e := o.Validate(c, args, f)
assert.Equal(t, e, nil)
e = o.Run(c, f)
assert.Contains(t, e.Error(), fmt.Sprintf("%s: no such file or directory", caCertFile))
// verify all options are set as expected
assert.Equal(t, name, o.Name)
assert.Equal(t, provider, o.Provider)
assert.Equal(t, bucket, o.Bucket)
assert.Equal(t, true, reflect.DeepEqual(credential, o.Credential))
assert.Equal(t, defaultBackupStorageLocation, o.DefaultBackupStorageLocation)
assert.Equal(t, prefix, o.Prefix)
assert.Equal(t, backupSyncPeriod, o.BackupSyncPeriod.String())
assert.Equal(t, validationFrequency, o.ValidationFrequency.String())
assert.Equal(t, true, reflect.DeepEqual(bslConfig, o.Config))
assert.Equal(t, true, test.CompareSlice(strings.Split(labels, ","), strings.Split(o.Labels.String(), ",")))
assert.Equal(t, caCertFile, o.CACertFile)
assert.Equal(t, accessMode, o.AccessMode.String())
// create the other create command without fromSchedule option for Run() other branches
c = NewCreateCommand(f, "velero backup-location create")
assert.Equal(t, "Create a backup storage location", c.Short)
o = NewCreateOptions()
o.Labels.Set("velero.io/test=true")
args = []string{"backup-name-2", "arg2"}
o.Complete(args, f)
e = o.Run(c, f)
assert.NoError(t, e)
c.SetArgs([]string{"bsl-1", "--provider=aws", "--bucket=bk1", "--default"})
e = c.Execute()
assert.NoError(t, e)
}

View File

@@ -0,0 +1,125 @@
/*
Copyright 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 backuplocation
import (
"fmt"
"os"
"os/exec"
"testing"
flag "github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
"github.com/vmware-tanzu/velero/pkg/cmd/cli"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
)
func TestNewDeleteCommand(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
client := &versionedmocks.Interface{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
// create command
c := NewDeleteCommand(f, "velero backup-location delete")
assert.Equal(t, "Delete backup storage locations", c.Short)
o := cli.NewDeleteOptions("backup")
flags := new(flag.FlagSet)
o.BindFlags(flags)
flags.Parse([]string{"--confirm"})
args := []string{"bk-loc-1", "bk-loc-2"}
e := o.Complete(f, args)
assert.NoError(t, e)
e = o.Validate(c, f, args)
assert.NoError(t, e)
c.SetArgs([]string{"bk-1", "--confirm"})
e = c.Execute()
assert.NoError(t, e)
e = Run(f, o)
assert.NoError(t, e)
if os.Getenv(cmdtest.CaptureFlag) == "1" {
return
}
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewDeleteCommand"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
stdout, _, err := veleroexec.RunCommand(cmd)
if err == nil {
assert.Contains(t, stdout, "No backup-locations found")
return
}
t.Fatalf("process ran with err %v, want backups by get()", err)
}
func TestDeleteFunctions(t *testing.T) {
//t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) {
// create a factory
f := &factorymocks.Factory{}
client := &versionedmocks.Interface{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
bkList := velerov1api.BackupList{}
bkrepoList := velerov1api.BackupRepositoryList{}
t.Run("findAssociatedBackups", func(t *testing.T) {
bkList, e := findAssociatedBackups(kbclient, "bk-loc-1", "ns1")
assert.Equal(t, 0, len(bkList.Items))
assert.NoError(t, e)
})
t.Run("findAssociatedBackupRepos", func(t *testing.T) {
bkrepoList, e := findAssociatedBackupRepos(kbclient, "bk-loc-1", "ns1")
assert.Equal(t, 0, len(bkrepoList.Items))
assert.NoError(t, e)
})
t.Run("deleteBackups", func(t *testing.T) {
bk := velerov1api.Backup{}
bk.Name = "bk-name-last"
bkList.Items = append(bkList.Items, bk)
errList := deleteBackups(kbclient, bkList)
assert.Equal(t, 1, len(errList))
assert.Contains(t, errList[0].Error(), fmt.Sprintf("delete backup \"%s\" associated with deleted BSL: backups.velero.io \"%s\" not found", bk.Name, bk.Name))
})
t.Run("deleteBackupRepos", func(t *testing.T) {
bkrepo := velerov1api.BackupRepository{}
bkrepo.Name = "bk-repo-name-last"
bkrepoList.Items = append(bkrepoList.Items, bkrepo)
errList := deleteBackupRepos(kbclient, bkrepoList)
assert.Equal(t, 1, len(errList))
assert.Contains(t, errList[0].Error(), fmt.Sprintf("delete backup repository \"%s\" associated with deleted BSL: backuprepositories.velero.io \"%s\" not found", bkrepo.Name, bkrepo.Name))
})
}

View File

@@ -0,0 +1,63 @@
/*
Copyright 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 backuplocation
import (
"fmt"
"os"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
)
func TestNewGetCommand(t *testing.T) {
bkList := []string{"b1", "b2"}
f := &factorymocks.Factory{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
// get command
c := NewGetCommand(f, "velero backup-location get")
assert.Equal(t, "Get backup storage locations", c.Short)
c.Execute()
if os.Getenv(cmdtest.CaptureFlag) == "1" {
c.SetArgs([]string{"b1", "b2", "--default"})
c.Execute()
return
}
cmd := exec.Command(os.Args[0], []string{"-test.run=TestNewGetCommand"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
_, stderr, err := veleroexec.RunCommand(cmd)
if err != nil {
assert.Contains(t, stderr, fmt.Sprintf("backupstoragelocations.velero.io \"%s\" not found", bkList[0]))
return
}
t.Fatalf("process ran with err %v, want backup delete successfully", err)
}

View File

@@ -0,0 +1,129 @@
/*
Copyright 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 backuplocation
import (
"fmt"
"os"
"os/exec"
"reflect"
"testing"
flag "github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
cmdtest "github.com/vmware-tanzu/velero/pkg/cmd/test"
veleroflag "github.com/vmware-tanzu/velero/pkg/cmd/util/flag"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
factorymocks "github.com/vmware-tanzu/velero/pkg/client/mocks"
versionedmocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/mocks"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
velerov1mocks "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1/mocks"
veleroexec "github.com/vmware-tanzu/velero/pkg/util/exec"
)
func TestNewSetCommand(t *testing.T) {
backupName := "arg2"
// create a config for factory
f := &factorymocks.Factory{}
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
bk := &velerov1api.Backup{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
backups.On("Create", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
// create command
c := NewSetCommand(f, "")
assert.Equal(t, "Set specific features for a backup storage location", c.Short)
// create a SetOptions with full options set and then run this backup command
cacert := "a/b/c/ut-cert.ca"
defaultBackupStorageLocation := true
credential := veleroflag.NewMap()
credential.Set("secret=a")
flags := new(flag.FlagSet)
o := NewSetOptions()
o.BindFlags(flags)
flags.Parse([]string{"--cacert", cacert})
flags.Parse([]string{"--credential", credential.String()})
flags.Parse([]string{"--default"})
args := []string{backupName}
o.Complete(args, f)
e := o.Validate(c, args, f)
assert.Equal(t, e, nil)
e = o.Run(c, f)
assert.Contains(t, e.Error(), fmt.Sprintf("%s: no such file or directory", cacert))
// verify all options are set as expected
assert.Equal(t, backupName, o.Name)
assert.Equal(t, cacert, o.CACertFile)
assert.Equal(t, defaultBackupStorageLocation, o.DefaultBackupStorageLocation)
assert.Equal(t, true, reflect.DeepEqual(credential, o.Credential))
assert.Contains(t, e.Error(), fmt.Sprintf("%s: no such file or directory", cacert))
}
func TestSetCommand_Execute(t *testing.T) {
bsl := "bsl-1"
if os.Getenv(cmdtest.CaptureFlag) == "1" {
// create a config for factory
f := &factorymocks.Factory{}
backups := &velerov1mocks.BackupInterface{}
veleroV1 := &velerov1mocks.VeleroV1Interface{}
client := &versionedmocks.Interface{}
bk := &velerov1api.Backup{}
kbclient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
backups.On("Create", mock.Anything, mock.Anything, mock.Anything).Return(bk, nil)
veleroV1.On("Backups", mock.Anything).Return(backups, nil)
client.On("VeleroV1").Return(veleroV1, nil)
f.On("Client").Return(client, nil)
f.On("Namespace").Return(mock.Anything)
f.On("KubebuilderClient").Return(kbclient, nil)
// create command
c := NewSetCommand(f, "velero backup-location set")
c.SetArgs([]string{bsl})
c.Execute()
return
}
cmd := exec.Command(os.Args[0], []string{"-test.run=TestSetCommand_Execute"}...)
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", cmdtest.CaptureFlag))
_, stderr, err := veleroexec.RunCommand(cmd)
if err != nil {
assert.Contains(t, stderr, fmt.Sprintf("backupstoragelocations.velero.io \"%s\" not found", bsl))
return
}
t.Fatalf("process ran with err %v, want backup delete successfully", err)
}

View File

@@ -125,18 +125,18 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
f := flags.VarPF(&o.RestoreVolumes, "restore-volumes", "", "Whether to restore volumes from snapshots.")
// this allows the user to just specify "--restore-volumes" as shorthand for "--restore-volumes=true"
// like a normal bool flag
f.NoOptDefVal = "true"
f.NoOptDefVal = cmd.TRUE
f = flags.VarPF(&o.PreserveNodePorts, "preserve-nodeports", "", "Whether to preserve nodeports of Services when restoring.")
// this allows the user to just specify "--preserve-nodeports" as shorthand for "--preserve-nodeports=true"
// like a normal bool flag
f.NoOptDefVal = "true"
f.NoOptDefVal = cmd.TRUE
f = flags.VarPF(&o.IncludeClusterResources, "include-cluster-resources", "", "Include cluster-scoped resources in the restore.")
f.NoOptDefVal = "true"
f.NoOptDefVal = cmd.TRUE
f = flags.VarPF(&o.AllowPartiallyFailed, "allow-partially-failed", "", "If using --from-schedule, whether to consider PartiallyFailed backups when looking for the most recent one. This flag has no effect if not using --from-schedule.")
f.NoOptDefVal = "true"
f.NoOptDefVal = cmd.TRUE
flags.BoolVarP(&o.Wait, "wait", "w", o.Wait, "Wait for the operation to complete.")
}

3
pkg/cmd/const.go Normal file
View File

@@ -0,0 +1,3 @@
package cmd
var TRUE string = "true"

4
pkg/cmd/test/const.go Normal file
View File

@@ -0,0 +1,4 @@
package test
var VeleroNameSpace string = "velero-test"
var CaptureFlag string = "CAPTRUE-OUTPUT"

View File

@@ -21,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/cmd"
)
var (
@@ -53,7 +54,7 @@ func printBackupStorageLocation(location *velerov1api.BackupStorageLocation) []m
isDefault := ""
if location.Spec.Default {
isDefault = "true"
isDefault = cmd.TRUE
}
bucketAndPrefix := location.Spec.ObjectStorage.Bucket

View File

@@ -1,4 +1,4 @@
// Code generated by mockery v2.28.1. DO NOT EDIT.
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
@@ -140,13 +140,12 @@ func (_m *Helper) ServerVersion() *version.Info {
return r0
}
type mockConstructorTestingTNewHelper interface {
// NewHelper creates a new instance of Helper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewHelper(t interface {
mock.TestingT
Cleanup(func())
}
// NewHelper creates a new instance of Helper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func NewHelper(t mockConstructorTestingTNewHelper) *Helper {
}) *Helper {
mock := &Helper{}
mock.Mock.Test(t)

View File

@@ -0,0 +1,79 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
mock "github.com/stretchr/testify/mock"
discovery "k8s.io/client-go/discovery"
v1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
v2alpha1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v2alpha1"
)
// Interface is an autogenerated mock type for the Interface type
type Interface struct {
mock.Mock
}
// Discovery provides a mock function with given fields:
func (_m *Interface) Discovery() discovery.DiscoveryInterface {
ret := _m.Called()
var r0 discovery.DiscoveryInterface
if rf, ok := ret.Get(0).(func() discovery.DiscoveryInterface); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(discovery.DiscoveryInterface)
}
}
return r0
}
// VeleroV1 provides a mock function with given fields:
func (_m *Interface) VeleroV1() v1.VeleroV1Interface {
ret := _m.Called()
var r0 v1.VeleroV1Interface
if rf, ok := ret.Get(0).(func() v1.VeleroV1Interface); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.VeleroV1Interface)
}
}
return r0
}
// VeleroV2alpha1 provides a mock function with given fields:
func (_m *Interface) VeleroV2alpha1() v2alpha1.VeleroV2alpha1Interface {
ret := _m.Called()
var r0 v2alpha1.VeleroV2alpha1Interface
if rf, ok := ret.Get(0).(func() v2alpha1.VeleroV2alpha1Interface); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v2alpha1.VeleroV2alpha1Interface)
}
}
return r0
}
// NewInterface creates a new instance of Interface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewInterface(t interface {
mock.TestingT
Cleanup(func())
}) *Interface {
mock := &Interface{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,252 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
context "context"
mock "github.com/stretchr/testify/mock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
watch "k8s.io/apimachinery/pkg/watch"
)
// BackupInterface is an autogenerated mock type for the BackupInterface type
type BackupInterface struct {
mock.Mock
}
// Create provides a mock function with given fields: ctx, backup, opts
func (_m *BackupInterface) Create(ctx context.Context, backup *v1.Backup, opts metav1.CreateOptions) (*v1.Backup, error) {
ret := _m.Called(ctx, backup, opts)
var r0 *v1.Backup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.Backup, metav1.CreateOptions) (*v1.Backup, error)); ok {
return rf(ctx, backup, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.Backup, metav1.CreateOptions) *v1.Backup); ok {
r0 = rf(ctx, backup, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Backup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.Backup, metav1.CreateOptions) error); ok {
r1 = rf(ctx, backup, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Delete provides a mock function with given fields: ctx, name, opts
func (_m *BackupInterface) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
ret := _m.Called(ctx, name, opts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.DeleteOptions) error); ok {
r0 = rf(ctx, name, opts)
} else {
r0 = ret.Error(0)
}
return r0
}
// DeleteCollection provides a mock function with given fields: ctx, opts, listOpts
func (_m *BackupInterface) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
ret := _m.Called(ctx, opts, listOpts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.DeleteOptions, metav1.ListOptions) error); ok {
r0 = rf(ctx, opts, listOpts)
} else {
r0 = ret.Error(0)
}
return r0
}
// Get provides a mock function with given fields: ctx, name, opts
func (_m *BackupInterface) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Backup, error) {
ret := _m.Called(ctx, name, opts)
var r0 *v1.Backup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) (*v1.Backup, error)); ok {
return rf(ctx, name, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) *v1.Backup); ok {
r0 = rf(ctx, name, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Backup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, metav1.GetOptions) error); ok {
r1 = rf(ctx, name, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// List provides a mock function with given fields: ctx, opts
func (_m *BackupInterface) List(ctx context.Context, opts metav1.ListOptions) (*v1.BackupList, error) {
ret := _m.Called(ctx, opts)
var r0 *v1.BackupList
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (*v1.BackupList, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) *v1.BackupList); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.BackupList)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Patch provides a mock function with given fields: ctx, name, pt, data, opts, subresources
func (_m *BackupInterface) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*v1.Backup, error) {
_va := make([]interface{}, len(subresources))
for _i := range subresources {
_va[_i] = subresources[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, name, pt, data, opts)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 *v1.Backup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) (*v1.Backup, error)); ok {
return rf(ctx, name, pt, data, opts, subresources...)
}
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) *v1.Backup); ok {
r0 = rf(ctx, name, pt, data, opts, subresources...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Backup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) error); ok {
r1 = rf(ctx, name, pt, data, opts, subresources...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Update provides a mock function with given fields: ctx, backup, opts
func (_m *BackupInterface) Update(ctx context.Context, backup *v1.Backup, opts metav1.UpdateOptions) (*v1.Backup, error) {
ret := _m.Called(ctx, backup, opts)
var r0 *v1.Backup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.Backup, metav1.UpdateOptions) (*v1.Backup, error)); ok {
return rf(ctx, backup, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.Backup, metav1.UpdateOptions) *v1.Backup); ok {
r0 = rf(ctx, backup, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Backup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.Backup, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, backup, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateStatus provides a mock function with given fields: ctx, backup, opts
func (_m *BackupInterface) UpdateStatus(ctx context.Context, backup *v1.Backup, opts metav1.UpdateOptions) (*v1.Backup, error) {
ret := _m.Called(ctx, backup, opts)
var r0 *v1.Backup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.Backup, metav1.UpdateOptions) (*v1.Backup, error)); ok {
return rf(ctx, backup, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.Backup, metav1.UpdateOptions) *v1.Backup); ok {
r0 = rf(ctx, backup, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Backup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.Backup, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, backup, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Watch provides a mock function with given fields: ctx, opts
func (_m *BackupInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
ret := _m.Called(ctx, opts)
var r0 watch.Interface
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (watch.Interface, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) watch.Interface); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(watch.Interface)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// NewBackupInterface creates a new instance of BackupInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewBackupInterface(t interface {
mock.TestingT
Cleanup(func())
}) *BackupInterface {
mock := &BackupInterface{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,43 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
mock "github.com/stretchr/testify/mock"
v1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
)
// BackupsGetter is an autogenerated mock type for the BackupsGetter type
type BackupsGetter struct {
mock.Mock
}
// Backups provides a mock function with given fields: namespace
func (_m *BackupsGetter) Backups(namespace string) v1.BackupInterface {
ret := _m.Called(namespace)
var r0 v1.BackupInterface
if rf, ok := ret.Get(0).(func(string) v1.BackupInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.BackupInterface)
}
}
return r0
}
// NewBackupsGetter creates a new instance of BackupsGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewBackupsGetter(t interface {
mock.TestingT
Cleanup(func())
}) *BackupsGetter {
mock := &BackupsGetter{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,252 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
context "context"
mock "github.com/stretchr/testify/mock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
watch "k8s.io/apimachinery/pkg/watch"
)
// DeleteBackupRequestInterface is an autogenerated mock type for the DeleteBackupRequestInterface type
type DeleteBackupRequestInterface struct {
mock.Mock
}
// Create provides a mock function with given fields: ctx, deleteBackupRequest, opts
func (_m *DeleteBackupRequestInterface) Create(ctx context.Context, deleteBackupRequest *v1.DeleteBackupRequest, opts metav1.CreateOptions) (*v1.DeleteBackupRequest, error) {
ret := _m.Called(ctx, deleteBackupRequest, opts)
var r0 *v1.DeleteBackupRequest
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.DeleteBackupRequest, metav1.CreateOptions) (*v1.DeleteBackupRequest, error)); ok {
return rf(ctx, deleteBackupRequest, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.DeleteBackupRequest, metav1.CreateOptions) *v1.DeleteBackupRequest); ok {
r0 = rf(ctx, deleteBackupRequest, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.DeleteBackupRequest)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.DeleteBackupRequest, metav1.CreateOptions) error); ok {
r1 = rf(ctx, deleteBackupRequest, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Delete provides a mock function with given fields: ctx, name, opts
func (_m *DeleteBackupRequestInterface) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
ret := _m.Called(ctx, name, opts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.DeleteOptions) error); ok {
r0 = rf(ctx, name, opts)
} else {
r0 = ret.Error(0)
}
return r0
}
// DeleteCollection provides a mock function with given fields: ctx, opts, listOpts
func (_m *DeleteBackupRequestInterface) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
ret := _m.Called(ctx, opts, listOpts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.DeleteOptions, metav1.ListOptions) error); ok {
r0 = rf(ctx, opts, listOpts)
} else {
r0 = ret.Error(0)
}
return r0
}
// Get provides a mock function with given fields: ctx, name, opts
func (_m *DeleteBackupRequestInterface) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.DeleteBackupRequest, error) {
ret := _m.Called(ctx, name, opts)
var r0 *v1.DeleteBackupRequest
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) (*v1.DeleteBackupRequest, error)); ok {
return rf(ctx, name, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) *v1.DeleteBackupRequest); ok {
r0 = rf(ctx, name, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.DeleteBackupRequest)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, metav1.GetOptions) error); ok {
r1 = rf(ctx, name, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// List provides a mock function with given fields: ctx, opts
func (_m *DeleteBackupRequestInterface) List(ctx context.Context, opts metav1.ListOptions) (*v1.DeleteBackupRequestList, error) {
ret := _m.Called(ctx, opts)
var r0 *v1.DeleteBackupRequestList
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (*v1.DeleteBackupRequestList, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) *v1.DeleteBackupRequestList); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.DeleteBackupRequestList)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Patch provides a mock function with given fields: ctx, name, pt, data, opts, subresources
func (_m *DeleteBackupRequestInterface) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*v1.DeleteBackupRequest, error) {
_va := make([]interface{}, len(subresources))
for _i := range subresources {
_va[_i] = subresources[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, name, pt, data, opts)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 *v1.DeleteBackupRequest
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) (*v1.DeleteBackupRequest, error)); ok {
return rf(ctx, name, pt, data, opts, subresources...)
}
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) *v1.DeleteBackupRequest); ok {
r0 = rf(ctx, name, pt, data, opts, subresources...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.DeleteBackupRequest)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) error); ok {
r1 = rf(ctx, name, pt, data, opts, subresources...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Update provides a mock function with given fields: ctx, deleteBackupRequest, opts
func (_m *DeleteBackupRequestInterface) Update(ctx context.Context, deleteBackupRequest *v1.DeleteBackupRequest, opts metav1.UpdateOptions) (*v1.DeleteBackupRequest, error) {
ret := _m.Called(ctx, deleteBackupRequest, opts)
var r0 *v1.DeleteBackupRequest
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.DeleteBackupRequest, metav1.UpdateOptions) (*v1.DeleteBackupRequest, error)); ok {
return rf(ctx, deleteBackupRequest, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.DeleteBackupRequest, metav1.UpdateOptions) *v1.DeleteBackupRequest); ok {
r0 = rf(ctx, deleteBackupRequest, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.DeleteBackupRequest)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.DeleteBackupRequest, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, deleteBackupRequest, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateStatus provides a mock function with given fields: ctx, deleteBackupRequest, opts
func (_m *DeleteBackupRequestInterface) UpdateStatus(ctx context.Context, deleteBackupRequest *v1.DeleteBackupRequest, opts metav1.UpdateOptions) (*v1.DeleteBackupRequest, error) {
ret := _m.Called(ctx, deleteBackupRequest, opts)
var r0 *v1.DeleteBackupRequest
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.DeleteBackupRequest, metav1.UpdateOptions) (*v1.DeleteBackupRequest, error)); ok {
return rf(ctx, deleteBackupRequest, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.DeleteBackupRequest, metav1.UpdateOptions) *v1.DeleteBackupRequest); ok {
r0 = rf(ctx, deleteBackupRequest, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.DeleteBackupRequest)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.DeleteBackupRequest, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, deleteBackupRequest, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Watch provides a mock function with given fields: ctx, opts
func (_m *DeleteBackupRequestInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
ret := _m.Called(ctx, opts)
var r0 watch.Interface
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (watch.Interface, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) watch.Interface); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(watch.Interface)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// NewDeleteBackupRequestInterface creates a new instance of DeleteBackupRequestInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewDeleteBackupRequestInterface(t interface {
mock.TestingT
Cleanup(func())
}) *DeleteBackupRequestInterface {
mock := &DeleteBackupRequestInterface{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,43 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
mock "github.com/stretchr/testify/mock"
v1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
)
// DeleteBackupRequestsGetter is an autogenerated mock type for the DeleteBackupRequestsGetter type
type DeleteBackupRequestsGetter struct {
mock.Mock
}
// DeleteBackupRequests provides a mock function with given fields: namespace
func (_m *DeleteBackupRequestsGetter) DeleteBackupRequests(namespace string) v1.DeleteBackupRequestInterface {
ret := _m.Called(namespace)
var r0 v1.DeleteBackupRequestInterface
if rf, ok := ret.Get(0).(func(string) v1.DeleteBackupRequestInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.DeleteBackupRequestInterface)
}
}
return r0
}
// NewDeleteBackupRequestsGetter creates a new instance of DeleteBackupRequestsGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewDeleteBackupRequestsGetter(t interface {
mock.TestingT
Cleanup(func())
}) *DeleteBackupRequestsGetter {
mock := &DeleteBackupRequestsGetter{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,252 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
context "context"
mock "github.com/stretchr/testify/mock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
watch "k8s.io/apimachinery/pkg/watch"
)
// PodVolumeBackupInterface is an autogenerated mock type for the PodVolumeBackupInterface type
type PodVolumeBackupInterface struct {
mock.Mock
}
// Create provides a mock function with given fields: ctx, podVolumeBackup, opts
func (_m *PodVolumeBackupInterface) Create(ctx context.Context, podVolumeBackup *v1.PodVolumeBackup, opts metav1.CreateOptions) (*v1.PodVolumeBackup, error) {
ret := _m.Called(ctx, podVolumeBackup, opts)
var r0 *v1.PodVolumeBackup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.PodVolumeBackup, metav1.CreateOptions) (*v1.PodVolumeBackup, error)); ok {
return rf(ctx, podVolumeBackup, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.PodVolumeBackup, metav1.CreateOptions) *v1.PodVolumeBackup); ok {
r0 = rf(ctx, podVolumeBackup, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.PodVolumeBackup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.PodVolumeBackup, metav1.CreateOptions) error); ok {
r1 = rf(ctx, podVolumeBackup, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Delete provides a mock function with given fields: ctx, name, opts
func (_m *PodVolumeBackupInterface) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
ret := _m.Called(ctx, name, opts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.DeleteOptions) error); ok {
r0 = rf(ctx, name, opts)
} else {
r0 = ret.Error(0)
}
return r0
}
// DeleteCollection provides a mock function with given fields: ctx, opts, listOpts
func (_m *PodVolumeBackupInterface) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
ret := _m.Called(ctx, opts, listOpts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.DeleteOptions, metav1.ListOptions) error); ok {
r0 = rf(ctx, opts, listOpts)
} else {
r0 = ret.Error(0)
}
return r0
}
// Get provides a mock function with given fields: ctx, name, opts
func (_m *PodVolumeBackupInterface) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.PodVolumeBackup, error) {
ret := _m.Called(ctx, name, opts)
var r0 *v1.PodVolumeBackup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) (*v1.PodVolumeBackup, error)); ok {
return rf(ctx, name, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) *v1.PodVolumeBackup); ok {
r0 = rf(ctx, name, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.PodVolumeBackup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, metav1.GetOptions) error); ok {
r1 = rf(ctx, name, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// List provides a mock function with given fields: ctx, opts
func (_m *PodVolumeBackupInterface) List(ctx context.Context, opts metav1.ListOptions) (*v1.PodVolumeBackupList, error) {
ret := _m.Called(ctx, opts)
var r0 *v1.PodVolumeBackupList
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (*v1.PodVolumeBackupList, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) *v1.PodVolumeBackupList); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.PodVolumeBackupList)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Patch provides a mock function with given fields: ctx, name, pt, data, opts, subresources
func (_m *PodVolumeBackupInterface) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*v1.PodVolumeBackup, error) {
_va := make([]interface{}, len(subresources))
for _i := range subresources {
_va[_i] = subresources[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, name, pt, data, opts)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 *v1.PodVolumeBackup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) (*v1.PodVolumeBackup, error)); ok {
return rf(ctx, name, pt, data, opts, subresources...)
}
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) *v1.PodVolumeBackup); ok {
r0 = rf(ctx, name, pt, data, opts, subresources...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.PodVolumeBackup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) error); ok {
r1 = rf(ctx, name, pt, data, opts, subresources...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Update provides a mock function with given fields: ctx, podVolumeBackup, opts
func (_m *PodVolumeBackupInterface) Update(ctx context.Context, podVolumeBackup *v1.PodVolumeBackup, opts metav1.UpdateOptions) (*v1.PodVolumeBackup, error) {
ret := _m.Called(ctx, podVolumeBackup, opts)
var r0 *v1.PodVolumeBackup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.PodVolumeBackup, metav1.UpdateOptions) (*v1.PodVolumeBackup, error)); ok {
return rf(ctx, podVolumeBackup, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.PodVolumeBackup, metav1.UpdateOptions) *v1.PodVolumeBackup); ok {
r0 = rf(ctx, podVolumeBackup, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.PodVolumeBackup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.PodVolumeBackup, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, podVolumeBackup, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateStatus provides a mock function with given fields: ctx, podVolumeBackup, opts
func (_m *PodVolumeBackupInterface) UpdateStatus(ctx context.Context, podVolumeBackup *v1.PodVolumeBackup, opts metav1.UpdateOptions) (*v1.PodVolumeBackup, error) {
ret := _m.Called(ctx, podVolumeBackup, opts)
var r0 *v1.PodVolumeBackup
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.PodVolumeBackup, metav1.UpdateOptions) (*v1.PodVolumeBackup, error)); ok {
return rf(ctx, podVolumeBackup, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.PodVolumeBackup, metav1.UpdateOptions) *v1.PodVolumeBackup); ok {
r0 = rf(ctx, podVolumeBackup, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.PodVolumeBackup)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.PodVolumeBackup, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, podVolumeBackup, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Watch provides a mock function with given fields: ctx, opts
func (_m *PodVolumeBackupInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
ret := _m.Called(ctx, opts)
var r0 watch.Interface
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (watch.Interface, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) watch.Interface); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(watch.Interface)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// NewPodVolumeBackupInterface creates a new instance of PodVolumeBackupInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewPodVolumeBackupInterface(t interface {
mock.TestingT
Cleanup(func())
}) *PodVolumeBackupInterface {
mock := &PodVolumeBackupInterface{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,252 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
context "context"
mock "github.com/stretchr/testify/mock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
watch "k8s.io/apimachinery/pkg/watch"
)
// ScheduleInterface is an autogenerated mock type for the ScheduleInterface type
type ScheduleInterface struct {
mock.Mock
}
// Create provides a mock function with given fields: ctx, schedule, opts
func (_m *ScheduleInterface) Create(ctx context.Context, schedule *v1.Schedule, opts metav1.CreateOptions) (*v1.Schedule, error) {
ret := _m.Called(ctx, schedule, opts)
var r0 *v1.Schedule
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.Schedule, metav1.CreateOptions) (*v1.Schedule, error)); ok {
return rf(ctx, schedule, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.Schedule, metav1.CreateOptions) *v1.Schedule); ok {
r0 = rf(ctx, schedule, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Schedule)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.Schedule, metav1.CreateOptions) error); ok {
r1 = rf(ctx, schedule, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Delete provides a mock function with given fields: ctx, name, opts
func (_m *ScheduleInterface) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
ret := _m.Called(ctx, name, opts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.DeleteOptions) error); ok {
r0 = rf(ctx, name, opts)
} else {
r0 = ret.Error(0)
}
return r0
}
// DeleteCollection provides a mock function with given fields: ctx, opts, listOpts
func (_m *ScheduleInterface) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
ret := _m.Called(ctx, opts, listOpts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.DeleteOptions, metav1.ListOptions) error); ok {
r0 = rf(ctx, opts, listOpts)
} else {
r0 = ret.Error(0)
}
return r0
}
// Get provides a mock function with given fields: ctx, name, opts
func (_m *ScheduleInterface) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Schedule, error) {
ret := _m.Called(ctx, name, opts)
var r0 *v1.Schedule
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) (*v1.Schedule, error)); ok {
return rf(ctx, name, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) *v1.Schedule); ok {
r0 = rf(ctx, name, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Schedule)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, metav1.GetOptions) error); ok {
r1 = rf(ctx, name, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// List provides a mock function with given fields: ctx, opts
func (_m *ScheduleInterface) List(ctx context.Context, opts metav1.ListOptions) (*v1.ScheduleList, error) {
ret := _m.Called(ctx, opts)
var r0 *v1.ScheduleList
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (*v1.ScheduleList, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) *v1.ScheduleList); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.ScheduleList)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Patch provides a mock function with given fields: ctx, name, pt, data, opts, subresources
func (_m *ScheduleInterface) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*v1.Schedule, error) {
_va := make([]interface{}, len(subresources))
for _i := range subresources {
_va[_i] = subresources[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, name, pt, data, opts)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 *v1.Schedule
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) (*v1.Schedule, error)); ok {
return rf(ctx, name, pt, data, opts, subresources...)
}
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) *v1.Schedule); ok {
r0 = rf(ctx, name, pt, data, opts, subresources...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Schedule)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) error); ok {
r1 = rf(ctx, name, pt, data, opts, subresources...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Update provides a mock function with given fields: ctx, schedule, opts
func (_m *ScheduleInterface) Update(ctx context.Context, schedule *v1.Schedule, opts metav1.UpdateOptions) (*v1.Schedule, error) {
ret := _m.Called(ctx, schedule, opts)
var r0 *v1.Schedule
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.Schedule, metav1.UpdateOptions) (*v1.Schedule, error)); ok {
return rf(ctx, schedule, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.Schedule, metav1.UpdateOptions) *v1.Schedule); ok {
r0 = rf(ctx, schedule, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Schedule)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.Schedule, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, schedule, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateStatus provides a mock function with given fields: ctx, schedule, opts
func (_m *ScheduleInterface) UpdateStatus(ctx context.Context, schedule *v1.Schedule, opts metav1.UpdateOptions) (*v1.Schedule, error) {
ret := _m.Called(ctx, schedule, opts)
var r0 *v1.Schedule
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.Schedule, metav1.UpdateOptions) (*v1.Schedule, error)); ok {
return rf(ctx, schedule, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.Schedule, metav1.UpdateOptions) *v1.Schedule); ok {
r0 = rf(ctx, schedule, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.Schedule)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.Schedule, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, schedule, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Watch provides a mock function with given fields: ctx, opts
func (_m *ScheduleInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
ret := _m.Called(ctx, opts)
var r0 watch.Interface
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (watch.Interface, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) watch.Interface); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(watch.Interface)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// NewScheduleInterface creates a new instance of ScheduleInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewScheduleInterface(t interface {
mock.TestingT
Cleanup(func())
}) *ScheduleInterface {
mock := &ScheduleInterface{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,43 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
mock "github.com/stretchr/testify/mock"
v1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
)
// SchedulesGetter is an autogenerated mock type for the SchedulesGetter type
type SchedulesGetter struct {
mock.Mock
}
// Schedules provides a mock function with given fields: namespace
func (_m *SchedulesGetter) Schedules(namespace string) v1.ScheduleInterface {
ret := _m.Called(namespace)
var r0 v1.ScheduleInterface
if rf, ok := ret.Get(0).(func(string) v1.ScheduleInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.ScheduleInterface)
}
}
return r0
}
// NewSchedulesGetter creates a new instance of SchedulesGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewSchedulesGetter(t interface {
mock.TestingT
Cleanup(func())
}) *SchedulesGetter {
mock := &SchedulesGetter{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,221 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
mock "github.com/stretchr/testify/mock"
rest "k8s.io/client-go/rest"
v1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
)
// VeleroV1Interface is an autogenerated mock type for the VeleroV1Interface type
type VeleroV1Interface struct {
mock.Mock
}
// BackupRepositories provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) BackupRepositories(namespace string) v1.BackupRepositoryInterface {
ret := _m.Called(namespace)
var r0 v1.BackupRepositoryInterface
if rf, ok := ret.Get(0).(func(string) v1.BackupRepositoryInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.BackupRepositoryInterface)
}
}
return r0
}
// BackupStorageLocations provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) BackupStorageLocations(namespace string) v1.BackupStorageLocationInterface {
ret := _m.Called(namespace)
var r0 v1.BackupStorageLocationInterface
if rf, ok := ret.Get(0).(func(string) v1.BackupStorageLocationInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.BackupStorageLocationInterface)
}
}
return r0
}
// Backups provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) Backups(namespace string) v1.BackupInterface {
ret := _m.Called(namespace)
var r0 v1.BackupInterface
if rf, ok := ret.Get(0).(func(string) v1.BackupInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.BackupInterface)
}
}
return r0
}
// DeleteBackupRequests provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) DeleteBackupRequests(namespace string) v1.DeleteBackupRequestInterface {
ret := _m.Called(namespace)
var r0 v1.DeleteBackupRequestInterface
if rf, ok := ret.Get(0).(func(string) v1.DeleteBackupRequestInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.DeleteBackupRequestInterface)
}
}
return r0
}
// DownloadRequests provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) DownloadRequests(namespace string) v1.DownloadRequestInterface {
ret := _m.Called(namespace)
var r0 v1.DownloadRequestInterface
if rf, ok := ret.Get(0).(func(string) v1.DownloadRequestInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.DownloadRequestInterface)
}
}
return r0
}
// PodVolumeBackups provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) PodVolumeBackups(namespace string) v1.PodVolumeBackupInterface {
ret := _m.Called(namespace)
var r0 v1.PodVolumeBackupInterface
if rf, ok := ret.Get(0).(func(string) v1.PodVolumeBackupInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.PodVolumeBackupInterface)
}
}
return r0
}
// PodVolumeRestores provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) PodVolumeRestores(namespace string) v1.PodVolumeRestoreInterface {
ret := _m.Called(namespace)
var r0 v1.PodVolumeRestoreInterface
if rf, ok := ret.Get(0).(func(string) v1.PodVolumeRestoreInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.PodVolumeRestoreInterface)
}
}
return r0
}
// RESTClient provides a mock function with given fields:
func (_m *VeleroV1Interface) RESTClient() rest.Interface {
ret := _m.Called()
var r0 rest.Interface
if rf, ok := ret.Get(0).(func() rest.Interface); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(rest.Interface)
}
}
return r0
}
// Restores provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) Restores(namespace string) v1.RestoreInterface {
ret := _m.Called(namespace)
var r0 v1.RestoreInterface
if rf, ok := ret.Get(0).(func(string) v1.RestoreInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.RestoreInterface)
}
}
return r0
}
// Schedules provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) Schedules(namespace string) v1.ScheduleInterface {
ret := _m.Called(namespace)
var r0 v1.ScheduleInterface
if rf, ok := ret.Get(0).(func(string) v1.ScheduleInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.ScheduleInterface)
}
}
return r0
}
// ServerStatusRequests provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) ServerStatusRequests(namespace string) v1.ServerStatusRequestInterface {
ret := _m.Called(namespace)
var r0 v1.ServerStatusRequestInterface
if rf, ok := ret.Get(0).(func(string) v1.ServerStatusRequestInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.ServerStatusRequestInterface)
}
}
return r0
}
// VolumeSnapshotLocations provides a mock function with given fields: namespace
func (_m *VeleroV1Interface) VolumeSnapshotLocations(namespace string) v1.VolumeSnapshotLocationInterface {
ret := _m.Called(namespace)
var r0 v1.VolumeSnapshotLocationInterface
if rf, ok := ret.Get(0).(func(string) v1.VolumeSnapshotLocationInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.VolumeSnapshotLocationInterface)
}
}
return r0
}
// NewVeleroV1Interface creates a new instance of VeleroV1Interface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewVeleroV1Interface(t interface {
mock.TestingT
Cleanup(func())
}) *VeleroV1Interface {
mock := &VeleroV1Interface{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,252 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
context "context"
mock "github.com/stretchr/testify/mock"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
watch "k8s.io/apimachinery/pkg/watch"
)
// VolumeSnapshotLocationInterface is an autogenerated mock type for the VolumeSnapshotLocationInterface type
type VolumeSnapshotLocationInterface struct {
mock.Mock
}
// Create provides a mock function with given fields: ctx, volumeSnapshotLocation, opts
func (_m *VolumeSnapshotLocationInterface) Create(ctx context.Context, volumeSnapshotLocation *v1.VolumeSnapshotLocation, opts metav1.CreateOptions) (*v1.VolumeSnapshotLocation, error) {
ret := _m.Called(ctx, volumeSnapshotLocation, opts)
var r0 *v1.VolumeSnapshotLocation
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.VolumeSnapshotLocation, metav1.CreateOptions) (*v1.VolumeSnapshotLocation, error)); ok {
return rf(ctx, volumeSnapshotLocation, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.VolumeSnapshotLocation, metav1.CreateOptions) *v1.VolumeSnapshotLocation); ok {
r0 = rf(ctx, volumeSnapshotLocation, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.VolumeSnapshotLocation)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.VolumeSnapshotLocation, metav1.CreateOptions) error); ok {
r1 = rf(ctx, volumeSnapshotLocation, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Delete provides a mock function with given fields: ctx, name, opts
func (_m *VolumeSnapshotLocationInterface) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
ret := _m.Called(ctx, name, opts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.DeleteOptions) error); ok {
r0 = rf(ctx, name, opts)
} else {
r0 = ret.Error(0)
}
return r0
}
// DeleteCollection provides a mock function with given fields: ctx, opts, listOpts
func (_m *VolumeSnapshotLocationInterface) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
ret := _m.Called(ctx, opts, listOpts)
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.DeleteOptions, metav1.ListOptions) error); ok {
r0 = rf(ctx, opts, listOpts)
} else {
r0 = ret.Error(0)
}
return r0
}
// Get provides a mock function with given fields: ctx, name, opts
func (_m *VolumeSnapshotLocationInterface) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.VolumeSnapshotLocation, error) {
ret := _m.Called(ctx, name, opts)
var r0 *v1.VolumeSnapshotLocation
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) (*v1.VolumeSnapshotLocation, error)); ok {
return rf(ctx, name, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, string, metav1.GetOptions) *v1.VolumeSnapshotLocation); ok {
r0 = rf(ctx, name, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.VolumeSnapshotLocation)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, metav1.GetOptions) error); ok {
r1 = rf(ctx, name, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// List provides a mock function with given fields: ctx, opts
func (_m *VolumeSnapshotLocationInterface) List(ctx context.Context, opts metav1.ListOptions) (*v1.VolumeSnapshotLocationList, error) {
ret := _m.Called(ctx, opts)
var r0 *v1.VolumeSnapshotLocationList
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (*v1.VolumeSnapshotLocationList, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) *v1.VolumeSnapshotLocationList); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.VolumeSnapshotLocationList)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Patch provides a mock function with given fields: ctx, name, pt, data, opts, subresources
func (_m *VolumeSnapshotLocationInterface) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*v1.VolumeSnapshotLocation, error) {
_va := make([]interface{}, len(subresources))
for _i := range subresources {
_va[_i] = subresources[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, name, pt, data, opts)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 *v1.VolumeSnapshotLocation
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) (*v1.VolumeSnapshotLocation, error)); ok {
return rf(ctx, name, pt, data, opts, subresources...)
}
if rf, ok := ret.Get(0).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) *v1.VolumeSnapshotLocation); ok {
r0 = rf(ctx, name, pt, data, opts, subresources...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.VolumeSnapshotLocation)
}
}
if rf, ok := ret.Get(1).(func(context.Context, string, types.PatchType, []byte, metav1.PatchOptions, ...string) error); ok {
r1 = rf(ctx, name, pt, data, opts, subresources...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Update provides a mock function with given fields: ctx, volumeSnapshotLocation, opts
func (_m *VolumeSnapshotLocationInterface) Update(ctx context.Context, volumeSnapshotLocation *v1.VolumeSnapshotLocation, opts metav1.UpdateOptions) (*v1.VolumeSnapshotLocation, error) {
ret := _m.Called(ctx, volumeSnapshotLocation, opts)
var r0 *v1.VolumeSnapshotLocation
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.VolumeSnapshotLocation, metav1.UpdateOptions) (*v1.VolumeSnapshotLocation, error)); ok {
return rf(ctx, volumeSnapshotLocation, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.VolumeSnapshotLocation, metav1.UpdateOptions) *v1.VolumeSnapshotLocation); ok {
r0 = rf(ctx, volumeSnapshotLocation, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.VolumeSnapshotLocation)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.VolumeSnapshotLocation, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, volumeSnapshotLocation, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateStatus provides a mock function with given fields: ctx, volumeSnapshotLocation, opts
func (_m *VolumeSnapshotLocationInterface) UpdateStatus(ctx context.Context, volumeSnapshotLocation *v1.VolumeSnapshotLocation, opts metav1.UpdateOptions) (*v1.VolumeSnapshotLocation, error) {
ret := _m.Called(ctx, volumeSnapshotLocation, opts)
var r0 *v1.VolumeSnapshotLocation
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v1.VolumeSnapshotLocation, metav1.UpdateOptions) (*v1.VolumeSnapshotLocation, error)); ok {
return rf(ctx, volumeSnapshotLocation, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, *v1.VolumeSnapshotLocation, metav1.UpdateOptions) *v1.VolumeSnapshotLocation); ok {
r0 = rf(ctx, volumeSnapshotLocation, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v1.VolumeSnapshotLocation)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v1.VolumeSnapshotLocation, metav1.UpdateOptions) error); ok {
r1 = rf(ctx, volumeSnapshotLocation, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// Watch provides a mock function with given fields: ctx, opts
func (_m *VolumeSnapshotLocationInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
ret := _m.Called(ctx, opts)
var r0 watch.Interface
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) (watch.Interface, error)); ok {
return rf(ctx, opts)
}
if rf, ok := ret.Get(0).(func(context.Context, metav1.ListOptions) watch.Interface); ok {
r0 = rf(ctx, opts)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(watch.Interface)
}
}
if rf, ok := ret.Get(1).(func(context.Context, metav1.ListOptions) error); ok {
r1 = rf(ctx, opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// NewVolumeSnapshotLocationInterface creates a new instance of VolumeSnapshotLocationInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewVolumeSnapshotLocationInterface(t interface {
mock.TestingT
Cleanup(func())
}) *VolumeSnapshotLocationInterface {
mock := &VolumeSnapshotLocationInterface{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -0,0 +1,43 @@
// Code generated by mockery v2.30.1. DO NOT EDIT.
package mocks
import (
mock "github.com/stretchr/testify/mock"
v1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
)
// VolumeSnapshotLocationsGetter is an autogenerated mock type for the VolumeSnapshotLocationsGetter type
type VolumeSnapshotLocationsGetter struct {
mock.Mock
}
// VolumeSnapshotLocations provides a mock function with given fields: namespace
func (_m *VolumeSnapshotLocationsGetter) VolumeSnapshotLocations(namespace string) v1.VolumeSnapshotLocationInterface {
ret := _m.Called(namespace)
var r0 v1.VolumeSnapshotLocationInterface
if rf, ok := ret.Get(0).(func(string) v1.VolumeSnapshotLocationInterface); ok {
r0 = rf(namespace)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(v1.VolumeSnapshotLocationInterface)
}
}
return r0
}
// NewVolumeSnapshotLocationsGetter creates a new instance of VolumeSnapshotLocationsGetter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewVolumeSnapshotLocationsGetter(t interface {
mock.TestingT
Cleanup(func())
}) *VolumeSnapshotLocationsGetter {
mock := &VolumeSnapshotLocationsGetter{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -36,6 +36,7 @@ type PodVolumeBackupsGetter interface {
PodVolumeBackups(namespace string) PodVolumeBackupInterface
}
//go:generate mockery --name PodVolumeBackupInterface
// PodVolumeBackupInterface has methods to work with PodVolumeBackup resources.
type PodVolumeBackupInterface interface {
Create(ctx context.Context, podVolumeBackup *v1.PodVolumeBackup, opts metav1.CreateOptions) (*v1.PodVolumeBackup, error)

View File

@@ -24,6 +24,8 @@ import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/equality"
@@ -118,3 +120,8 @@ func AssertErrorMatches(t *testing.T, expected string, actual error) bool {
return assert.NoError(t, actual)
}
func CompareSlice(x, y []string) bool {
less := func(a, b string) bool { return a < b }
return cmp.Diff(x, y, cmpopts.SortSlices(less)) == ""
}