Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions velero-plugins/buildconfig/restore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package buildconfig

import (
"testing"

"github.com/konveyor/openshift-velero-plugin/velero-plugins/util/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)

func TestRestorePluginAppliesTo(t *testing.T) {
restorePlugin := &RestorePlugin{Log: test.NewLogger()}
actual, err := restorePlugin.AppliesTo()
require.NoError(t, err)
assert.Equal(t, velero.ResourceSelector{IncludedResources: []string{"buildconfigs"}}, actual)
}

// Note: Execute() functionality is tested through:
// - build.UpdateCommonSpec() tests in build/restore_test.go which handles:
// - Docker image reference swapping from backup to restore registry
// - Pull/push secret updates to match destination cluster
// - common.GetSrcAndDestRegistryInfo() tests for registry info extraction
// The updateSecretsAndDockerRefs() helper function wraps these tested components.
24 changes: 24 additions & 0 deletions velero-plugins/clusterrolebindings/restore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package clusterrolebindings

import (
"testing"

"github.com/konveyor/openshift-velero-plugin/velero-plugins/util/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)

func TestRestorePluginAppliesTo(t *testing.T) {
restorePlugin := &RestorePlugin{Log: test.NewLogger()}
actual, err := restorePlugin.AppliesTo()
require.NoError(t, err)
assert.Equal(t, velero.ResourceSelector{IncludedResources: []string{"clusterrolebinding.authorization.openshift.io"}}, actual)
}

// Note: Execute() functionality is tested through:
// - rolebindings/restore_test.go tests the namespace mapping helper functions:
// - SwapSubjectNamespaces(): Updates subject namespaces based on namespace mapping
// - SwapUserNamesNamespaces(): Updates UserNames with service account namespace format
// - SwapGroupNamesNamespaces(): Updates GroupNames with system:serviceaccounts namespace format
// These same functions are used by ClusterRoleBindings Execute() method.
89 changes: 89 additions & 0 deletions velero-plugins/configmap/restore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package configmap

import (
"testing"

"github.com/konveyor/openshift-velero-plugin/velero-plugins/common"
"github.com/konveyor/openshift-velero-plugin/velero-plugins/util/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

func TestRestorePluginAppliesTo(t *testing.T) {
restorePlugin := &RestorePlugin{Log: test.NewLogger()}
actual, err := restorePlugin.AppliesTo()
require.NoError(t, err)
assert.Equal(t, velero.ResourceSelector{IncludedResources: []string{"configmaps"}}, actual)
}

func TestExecute(t *testing.T) {
restorePlugin := &RestorePlugin{Log: test.NewLogger()}

tests := []struct {
name string
annotations map[string]string
expectSkipRestore bool
}{
{
name: "ConfigMap with no annotations",
annotations: nil,
expectSkipRestore: false,
},
{
name: "ConfigMap with empty annotations",
annotations: map[string]string{},
expectSkipRestore: false,
},
{
name: "ConfigMap with skip annotation set to true",
annotations: map[string]string{
common.SkipBuildConfigConfigMapRestore: "true",
},
expectSkipRestore: true,
},
{
name: "ConfigMap with skip annotation set to false",
annotations: map[string]string{
common.SkipBuildConfigConfigMapRestore: "false",
},
expectSkipRestore: false,
},
{
name: "ConfigMap with skip annotation set to invalid value",
annotations: map[string]string{
common.SkipBuildConfigConfigMapRestore: "invalid",
},
expectSkipRestore: false,
},
{
name: "ConfigMap with other annotations",
annotations: map[string]string{
"some-other-annotation": "value",
},
expectSkipRestore: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
item := &unstructured.Unstructured{}
item.SetAPIVersion("v1")
item.SetKind("ConfigMap")
item.SetNamespace("test-ns")
item.SetName("test-configmap")
if tt.annotations != nil {
item.SetAnnotations(tt.annotations)
}

input := &velero.RestoreItemActionExecuteInput{
Item: item,
}

output, err := restorePlugin.Execute(input)
require.NoError(t, err)
assert.Equal(t, tt.expectSkipRestore, output.SkipRestore)
})
}
}
22 changes: 22 additions & 0 deletions velero-plugins/cronjob/restore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cronjob

import (
"testing"

"github.com/konveyor/openshift-velero-plugin/velero-plugins/util/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)

func TestRestorePluginAppliesTo(t *testing.T) {
restorePlugin := &RestorePlugin{Log: test.NewLogger()}
actual, err := restorePlugin.AppliesTo()
require.NoError(t, err)
assert.Equal(t, velero.ResourceSelector{IncludedResources: []string{"cronjobs"}}, actual)
}

// Note: Execute() functionality is tested through:
// - common.GetSrcAndDestRegistryInfo() tests for extracting registry info from annotations
// - common.SwapContainerImageRefs() tests for swapping image references from backup to restore registry
// The Execute() method uses these tested components to update container and init container images.
22 changes: 22 additions & 0 deletions velero-plugins/daemonset/restore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package daemonset

import (
"testing"

"github.com/konveyor/openshift-velero-plugin/velero-plugins/util/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)

func TestRestorePluginAppliesTo(t *testing.T) {
restorePlugin := &RestorePlugin{Log: test.NewLogger()}
actual, err := restorePlugin.AppliesTo()
require.NoError(t, err)
assert.Equal(t, velero.ResourceSelector{IncludedResources: []string{"daemonsets.apps"}}, actual)
}

// Note: Execute() functionality is tested through:
// - common.GetSrcAndDestRegistryInfo() tests for extracting registry info from annotations
// - common.SwapContainerImageRefs() tests for swapping image references from backup to restore registry
// The Execute() method uses these tested components to update container and init container images.
22 changes: 22 additions & 0 deletions velero-plugins/deployment/restore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package deployment

import (
"testing"

"github.com/konveyor/openshift-velero-plugin/velero-plugins/util/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)

func TestRestorePluginAppliesTo(t *testing.T) {
restorePlugin := &RestorePlugin{Log: test.NewLogger()}
actual, err := restorePlugin.AppliesTo()
require.NoError(t, err)
assert.Equal(t, velero.ResourceSelector{IncludedResources: []string{"deployments.apps"}}, actual)
}

// Note: Execute() functionality is tested through:
// - common.GetSrcAndDestRegistryInfo() tests for extracting registry info from annotations
// - common.SwapContainerImageRefs() tests for swapping image references from backup to restore registry
// The Execute() method uses these tested components to update container and init container images.
26 changes: 26 additions & 0 deletions velero-plugins/deploymentconfig/restore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package deploymentconfig

import (
"testing"

"github.com/konveyor/openshift-velero-plugin/velero-plugins/util/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)

func TestRestorePluginAppliesTo(t *testing.T) {
restorePlugin := &RestorePlugin{Log: test.NewLogger()}
actual, err := restorePlugin.AppliesTo()
require.NoError(t, err)
assert.Equal(t, velero.ResourceSelector{IncludedResources: []string{"deploymentconfigs"}}, actual)
}

// Note: Execute() functionality is tested through:
// - common.GetSrcAndDestRegistryInfo() tests for extracting registry info from annotations
// - common.SwapContainerImageRefs() tests for swapping image references from backup to restore registry
// - pod/restore_test.go tests PodHasVolumesToBackUp() and PodHasRestoreHooks() used for DC pod handling
// Additional DC-specific functionality:
// - Image change trigger namespace mapping (when namespace mapping is enabled)
// - Special pod restoration logic (setting replicas=0 when pods have volumes/hooks to prevent deletion)
// These would typically be tested in integration tests due to their complex dependencies.
Loading