mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-20 06:54:32 +00:00
add unit test for getDefaultVolumeSnapshotLocations
Signed-off-by: Wayne Witzel III <wayne@riotousliving.com>
This commit is contained in:
committed by
Steve Kriss
parent
02f50b9c84
commit
4af89fa863
@@ -25,6 +25,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/heptio/ark/pkg/apis/ark/v1"
|
||||
fakeclientset "github.com/heptio/ark/pkg/generated/clientset/versioned/fake"
|
||||
arktest "github.com/heptio/ark/pkg/util/test"
|
||||
)
|
||||
|
||||
@@ -97,3 +98,59 @@ func TestArkResourcesExist(t *testing.T) {
|
||||
arkAPIResourceList.APIResources = arkAPIResourceList.APIResources[:3]
|
||||
assert.Error(t, server.arkResourcesExist())
|
||||
}
|
||||
|
||||
func TestDefaultVolumeSnapshotLocations(t *testing.T) {
|
||||
namespace := "heptio-ark"
|
||||
arkClient := fakeclientset.NewSimpleClientset()
|
||||
|
||||
location := &v1.VolumeSnapshotLocation{ObjectMeta: metav1.ObjectMeta{Name: "location1"}, Spec: v1.VolumeSnapshotLocationSpec{Provider: "provider1"}}
|
||||
arkClient.ArkV1().VolumeSnapshotLocations(namespace).Create(location)
|
||||
|
||||
defaultVolumeSnapshotLocations := make(map[string]string)
|
||||
|
||||
// No defaults
|
||||
volumeSnapshotLocations, err := getDefaultVolumeSnapshotLocations(arkClient, namespace, defaultVolumeSnapshotLocations)
|
||||
assert.Equal(t, 0, len(volumeSnapshotLocations))
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Bad location
|
||||
defaultVolumeSnapshotLocations["provider1"] = "badlocation"
|
||||
volumeSnapshotLocations, err = getDefaultVolumeSnapshotLocations(arkClient, namespace, defaultVolumeSnapshotLocations)
|
||||
assert.Equal(t, 0, len(volumeSnapshotLocations))
|
||||
assert.Error(t, err)
|
||||
|
||||
// Bad provider
|
||||
defaultVolumeSnapshotLocations["provider2"] = "badlocation"
|
||||
volumeSnapshotLocations, err = getDefaultVolumeSnapshotLocations(arkClient, namespace, defaultVolumeSnapshotLocations)
|
||||
assert.Equal(t, 0, len(volumeSnapshotLocations))
|
||||
assert.Error(t, err)
|
||||
|
||||
// Good provider, good location
|
||||
delete(defaultVolumeSnapshotLocations, "provider2")
|
||||
defaultVolumeSnapshotLocations["provider1"] = "location1"
|
||||
volumeSnapshotLocations, err = getDefaultVolumeSnapshotLocations(arkClient, namespace, defaultVolumeSnapshotLocations)
|
||||
assert.Equal(t, 1, len(volumeSnapshotLocations))
|
||||
assert.NoError(t, err)
|
||||
|
||||
location2 := &v1.VolumeSnapshotLocation{ObjectMeta: metav1.ObjectMeta{Name: "location2"}, Spec: v1.VolumeSnapshotLocationSpec{Provider: "provider2"}}
|
||||
arkClient.ArkV1().VolumeSnapshotLocations(namespace).Create(location2)
|
||||
|
||||
// Mutliple Provider/Location 1 good, 1 bad
|
||||
defaultVolumeSnapshotLocations["provider2"] = "badlocation"
|
||||
volumeSnapshotLocations, err = getDefaultVolumeSnapshotLocations(arkClient, namespace, defaultVolumeSnapshotLocations)
|
||||
assert.Error(t, err)
|
||||
|
||||
location21 := &v1.VolumeSnapshotLocation{ObjectMeta: metav1.ObjectMeta{Name: "location2-1"}, Spec: v1.VolumeSnapshotLocationSpec{Provider: "provider2"}}
|
||||
arkClient.ArkV1().VolumeSnapshotLocations(namespace).Create(location21)
|
||||
|
||||
location11 := &v1.VolumeSnapshotLocation{ObjectMeta: metav1.ObjectMeta{Name: "location1-1"}, Spec: v1.VolumeSnapshotLocationSpec{Provider: "provider1"}}
|
||||
arkClient.ArkV1().VolumeSnapshotLocations(namespace).Create(location11)
|
||||
|
||||
// Mutliple Provider/Location all good
|
||||
defaultVolumeSnapshotLocations["provider2"] = "location2"
|
||||
volumeSnapshotLocations, err = getDefaultVolumeSnapshotLocations(arkClient, namespace, defaultVolumeSnapshotLocations)
|
||||
assert.Equal(t, 2, len(volumeSnapshotLocations))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, volumeSnapshotLocations["provider1"].ObjectMeta.Name, "location1")
|
||||
assert.Equal(t, volumeSnapshotLocations["provider2"].ObjectMeta.Name, "location2")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user