diff --git a/pkg/backup/backup_test.go b/pkg/backup/backup_test.go index 06fdfbe85..5826b8ec4 100644 --- a/pkg/backup/backup_test.go +++ b/pkg/backup/backup_test.go @@ -96,8 +96,8 @@ func TestResolveActions(t *testing.T) { name: "resolved", input: map[string]Action{"foo": &fakeAction{}, "bar": &fakeAction{}}, expected: map[schema.GroupResource]Action{ - schema.GroupResource{Group: "somegroup", Resource: "foodies"}: &fakeAction{}, - schema.GroupResource{Group: "anothergroup", Resource: "barnacles"}: &fakeAction{}, + {Group: "somegroup", Resource: "foodies"}: &fakeAction{}, + {Group: "anothergroup", Resource: "barnacles"}: &fakeAction{}, }, }, } @@ -105,10 +105,10 @@ func TestResolveActions(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { resources := map[schema.GroupVersionResource]schema.GroupVersionResource{ - schema.GroupVersionResource{Resource: "foo"}: schema.GroupVersionResource{Group: "somegroup", Resource: "foodies"}, - schema.GroupVersionResource{Resource: "fie"}: schema.GroupVersionResource{Group: "somegroup", Resource: "fields"}, - schema.GroupVersionResource{Resource: "bar"}: schema.GroupVersionResource{Group: "anothergroup", Resource: "barnacles"}, - schema.GroupVersionResource{Resource: "baz"}: schema.GroupVersionResource{Group: "anothergroup", Resource: "bazaars"}, + {Resource: "foo"}: {Group: "somegroup", Resource: "foodies"}, + {Resource: "fie"}: {Group: "somegroup", Resource: "fields"}, + {Resource: "bar"}: {Group: "anothergroup", Resource: "barnacles"}, + {Resource: "baz"}: {Group: "anothergroup", Resource: "bazaars"}, } discoveryHelper := arktest.NewFakeDiscoveryHelper(false, resources) @@ -174,10 +174,10 @@ func TestGetResourceIncludesExcludes(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { resources := map[schema.GroupVersionResource]schema.GroupVersionResource{ - schema.GroupVersionResource{Resource: "foo"}: schema.GroupVersionResource{Group: "somegroup", Resource: "foodies"}, - schema.GroupVersionResource{Resource: "fie"}: schema.GroupVersionResource{Group: "somegroup", Resource: "fields"}, - schema.GroupVersionResource{Resource: "bar"}: schema.GroupVersionResource{Group: "anothergroup", Resource: "barnacles"}, - schema.GroupVersionResource{Resource: "baz"}: schema.GroupVersionResource{Group: "anothergroup", Resource: "bazaars"}, + {Resource: "foo"}: {Group: "somegroup", Resource: "foodies"}, + {Resource: "fie"}: {Group: "somegroup", Resource: "fields"}, + {Resource: "bar"}: {Group: "anothergroup", Resource: "barnacles"}, + {Resource: "baz"}: {Group: "anothergroup", Resource: "bazaars"}, } discoveryHelper := arktest.NewFakeDiscoveryHelper(false, resources) @@ -463,9 +463,9 @@ func TestBackup(t *testing.T) { discoveryHelper := &arktest.FakeDiscoveryHelper{ Mapper: &arktest.FakeMapper{ Resources: map[schema.GroupVersionResource]schema.GroupVersionResource{ - schema.GroupVersionResource{Resource: "cm"}: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmaps"}, - schema.GroupVersionResource{Resource: "csr"}: schema.GroupVersionResource{Group: "certificates.k8s.io", Version: "v1beta1", Resource: "certificatesigningrequests"}, - schema.GroupVersionResource{Resource: "roles"}: schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1beta1", Resource: "roles"}, + {Resource: "cm"}: {Group: "", Version: "v1", Resource: "configmaps"}, + {Resource: "csr"}: {Group: "certificates.k8s.io", Version: "v1beta1", Resource: "certificatesigningrequests"}, + {Resource: "roles"}: {Group: "rbac.authorization.k8s.io", Version: "v1beta1", Resource: "roles"}, }, }, ResourceList: []*metav1.APIResourceList{ diff --git a/pkg/backup/group_backupper_test.go b/pkg/backup/group_backupper_test.go index a5a57daff..e345750dd 100644 --- a/pkg/backup/group_backupper_test.go +++ b/pkg/backup/group_backupper_test.go @@ -45,7 +45,7 @@ func TestBackupGroup(t *testing.T) { discoveryHelper := arktest.NewFakeDiscoveryHelper(true, nil) backedUpItems := map[itemKey]struct{}{ - {resource: "a", namespace: "b", name: "c"}: struct{}{}, + {resource: "a", namespace: "b", name: "c"}: {}, } cohabitatingResources := map[string]*cohabitatingResource{ @@ -57,7 +57,7 @@ func TestBackupGroup(t *testing.T) { } actions := map[schema.GroupResource]Action{ - schema.GroupResource{Group: "", Resource: "pods"}: &fakeAction{}, + {Group: "", Resource: "pods"}: &fakeAction{}, } podCommandExecutor := &mockPodCommandExecutor{} diff --git a/pkg/backup/item_backupper_test.go b/pkg/backup/item_backupper_test.go index 240658467..a59fdc9b6 100644 --- a/pkg/backup/item_backupper_test.go +++ b/pkg/backup/item_backupper_test.go @@ -83,7 +83,7 @@ func TestBackupItemSkips(t *testing.T) { namespaces: collections.NewIncludesExcludes(), resources: collections.NewIncludesExcludes(), backedUpItems: map[itemKey]struct{}{ - {resource: "bar.foo", namespace: "ns", name: "foo"}: struct{}{}, + {resource: "bar.foo", namespace: "ns", name: "foo"}: {}, }, }, } diff --git a/pkg/backup/resource_backupper_test.go b/pkg/backup/resource_backupper_test.go index 78b7828df..deb088cd2 100644 --- a/pkg/backup/resource_backupper_test.go +++ b/pkg/backup/resource_backupper_test.go @@ -212,7 +212,7 @@ func TestBackupResource(t *testing.T) { discoveryHelper := arktest.NewFakeDiscoveryHelper(true, nil) backedUpItems := map[itemKey]struct{}{ - {resource: "foo", namespace: "ns", name: "name"}: struct{}{}, + {resource: "foo", namespace: "ns", name: "name"}: {}, } cohabitatingResources := map[string]*cohabitatingResource{ @@ -352,7 +352,7 @@ func TestBackupResourceCohabitation(t *testing.T) { discoveryHelper := arktest.NewFakeDiscoveryHelper(true, nil) backedUpItems := map[itemKey]struct{}{ - {resource: "foo", namespace: "ns", name: "name"}: struct{}{}, + {resource: "foo", namespace: "ns", name: "name"}: {}, } cohabitatingResources := map[string]*cohabitatingResource{ diff --git a/pkg/backup/volume_snapshot_action_test.go b/pkg/backup/volume_snapshot_action_test.go index 7e36954a6..b8dd9e5eb 100644 --- a/pkg/backup/volume_snapshot_action_test.go +++ b/pkg/backup/volume_snapshot_action_test.go @@ -83,7 +83,7 @@ func TestVolumeSnapshotAction(t *testing.T) { expectedVolumeID: "vol-abc123", ttl: 5 * time.Minute, volumeInfo: map[string]v1.VolumeBackupInfo{ - "vol-abc123": v1.VolumeBackupInfo{Type: "gp", SnapshotID: "snap-1", AvailabilityZone: "us-east-1c"}, + "vol-abc123": {Type: "gp", SnapshotID: "snap-1", AvailabilityZone: "us-east-1c"}, }, }, { @@ -95,7 +95,7 @@ func TestVolumeSnapshotAction(t *testing.T) { expectedVolumeID: "vol-abc123", ttl: 5 * time.Minute, volumeInfo: map[string]v1.VolumeBackupInfo{ - "vol-abc123": v1.VolumeBackupInfo{Type: "io1", Iops: &iops, SnapshotID: "snap-1", AvailabilityZone: "us-east-1c"}, + "vol-abc123": {Type: "io1", Iops: &iops, SnapshotID: "snap-1", AvailabilityZone: "us-east-1c"}, }, }, { @@ -107,7 +107,7 @@ func TestVolumeSnapshotAction(t *testing.T) { expectedVolumeID: "vol-abc123", ttl: 5 * time.Minute, volumeInfo: map[string]v1.VolumeBackupInfo{ - "vol-abc123": v1.VolumeBackupInfo{Type: "gp", SnapshotID: "snap-1", AvailabilityZone: "us-west-2a"}, + "vol-abc123": {Type: "gp", SnapshotID: "snap-1", AvailabilityZone: "us-west-2a"}, }, }, { @@ -119,7 +119,7 @@ func TestVolumeSnapshotAction(t *testing.T) { expectedVolumeID: "pd-abc123", ttl: 5 * time.Minute, volumeInfo: map[string]v1.VolumeBackupInfo{ - "pd-abc123": v1.VolumeBackupInfo{Type: "gp", SnapshotID: "snap-1", AvailabilityZone: "gcp-zone2"}, + "pd-abc123": {Type: "gp", SnapshotID: "snap-1", AvailabilityZone: "gcp-zone2"}, }, }, { @@ -131,7 +131,7 @@ func TestVolumeSnapshotAction(t *testing.T) { expectedVolumeID: "foo-disk", ttl: 5 * time.Minute, volumeInfo: map[string]v1.VolumeBackupInfo{ - "foo-disk": v1.VolumeBackupInfo{Type: "gp", SnapshotID: "snap-1"}, + "foo-disk": {Type: "gp", SnapshotID: "snap-1"}, }, }, { @@ -143,10 +143,10 @@ func TestVolumeSnapshotAction(t *testing.T) { expectedVolumeID: "pd-abc123", ttl: 5 * time.Minute, existingVolumeBackups: map[string]*v1.VolumeBackupInfo{ - "anotherpv": &v1.VolumeBackupInfo{SnapshotID: "anothersnap"}, + "anotherpv": {SnapshotID: "anothersnap"}, }, volumeInfo: map[string]v1.VolumeBackupInfo{ - "pd-abc123": v1.VolumeBackupInfo{Type: "gp", SnapshotID: "snap-1"}, + "pd-abc123": {Type: "gp", SnapshotID: "snap-1"}, }, }, { @@ -164,7 +164,7 @@ func TestVolumeSnapshotAction(t *testing.T) { expectedVolumeID: "vol-abc123", ttl: 5 * time.Minute, volumeInfo: map[string]v1.VolumeBackupInfo{ - "vol-abc123": v1.VolumeBackupInfo{Type: "gp", SnapshotID: "snap-1"}, + "vol-abc123": {Type: "gp", SnapshotID: "snap-1"}, }, }, } diff --git a/pkg/cloudprovider/backup_service_test.go b/pkg/cloudprovider/backup_service_test.go index b7a7af5e1..b970baabb 100644 --- a/pkg/cloudprovider/backup_service_test.go +++ b/pkg/cloudprovider/backup_service_test.go @@ -201,11 +201,11 @@ func TestGetAllBackups(t *testing.T) { "backup-2/ark-backup.json": encodeToBytes(&api.Backup{ObjectMeta: metav1.ObjectMeta{Name: "backup-2"}}), }, expectedRes: []*api.Backup{ - &api.Backup{ + { TypeMeta: metav1.TypeMeta{Kind: "Backup", APIVersion: "ark.heptio.com/v1"}, ObjectMeta: metav1.ObjectMeta{Name: "backup-1"}, }, - &api.Backup{ + { TypeMeta: metav1.TypeMeta{Kind: "Backup", APIVersion: "ark.heptio.com/v1"}, ObjectMeta: metav1.ObjectMeta{Name: "backup-2"}, }, @@ -218,7 +218,7 @@ func TestGetAllBackups(t *testing.T) { "backup-2/ark-backup.json": []byte("this is not valid backup JSON"), }, expectedRes: []*api.Backup{ - &api.Backup{ + { TypeMeta: metav1.TypeMeta{Kind: "Backup", APIVersion: "ark.heptio.com/v1"}, ObjectMeta: metav1.ObjectMeta{Name: "backup-1"}, }, diff --git a/pkg/cmd/util/output/backup_printer_test.go b/pkg/cmd/util/output/backup_printer_test.go index 355ef23a0..2dc32b27e 100644 --- a/pkg/cmd/util/output/backup_printer_test.go +++ b/pkg/cmd/util/output/backup_printer_test.go @@ -35,42 +35,42 @@ func TestSortBackups(t *testing.T) { { name: "non-timestamped backups", backupList: &v1.BackupList{Items: []v1.Backup{ - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "a"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "c"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "b"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "a"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "c"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "b"}}, }}, expected: []v1.Backup{ - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "a"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "b"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "c"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "a"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "b"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "c"}}, }, }, { name: "timestamped backups", backupList: &v1.BackupList{Items: []v1.Backup{ - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030405"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030406"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030407"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030405"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030406"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030407"}}, }}, expected: []v1.Backup{ - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030407"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030406"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030405"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030407"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030406"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030405"}}, }, }, { name: "non-timestamped and timestamped backups", backupList: &v1.BackupList{Items: []v1.Backup{ - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030405"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030406"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "a"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030407"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030405"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030406"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "a"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030407"}}, }}, expected: []v1.Backup{ - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "a"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030407"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030406"}}, - v1.Backup{ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030405"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "a"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030407"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030406"}}, + {ObjectMeta: metav1.ObjectMeta{Name: "schedule-20170102030405"}}, }, }, } diff --git a/pkg/controller/gc_controller_test.go b/pkg/controller/gc_controller_test.go index 5e9d25d67..1d51955e4 100644 --- a/pkg/controller/gc_controller_test.go +++ b/pkg/controller/gc_controller_test.go @@ -48,7 +48,7 @@ func TestGarbageCollect(t *testing.T) { fakeClock := clock.NewFakeClock(time.Now()) tests := []gcTest{ - gcTest{ + { name: "basic-expired", backups: []*api.Backup{ NewTestBackup().WithName("backup-1"). @@ -61,7 +61,7 @@ func TestGarbageCollect(t *testing.T) { expectedDeletions: sets.NewString("backup-1"), expectedSnapshotsRemaining: sets.NewString(), }, - gcTest{ + { name: "basic-unexpired", backups: []*api.Backup{ NewTestBackup().WithName("backup-1"). @@ -74,7 +74,7 @@ func TestGarbageCollect(t *testing.T) { expectedDeletions: sets.NewString(), expectedSnapshotsRemaining: sets.NewString("snapshot-1", "snapshot-2"), }, - gcTest{ + { name: "one expired, one unexpired", backups: []*api.Backup{ NewTestBackup().WithName("backup-1"). @@ -92,7 +92,7 @@ func TestGarbageCollect(t *testing.T) { expectedDeletions: sets.NewString("backup-1"), expectedSnapshotsRemaining: sets.NewString("snapshot-3", "snapshot-4"), }, - gcTest{ + { name: "none expired in target bucket", backups: []*api.Backup{ NewTestBackup().WithName("backup-2"). @@ -105,7 +105,7 @@ func TestGarbageCollect(t *testing.T) { expectedDeletions: sets.NewString(), expectedSnapshotsRemaining: sets.NewString("snapshot-1", "snapshot-2", "snapshot-3", "snapshot-4"), }, - gcTest{ + { name: "orphan snapshots", backups: []*api.Backup{ NewTestBackup().WithName("backup-1"). @@ -118,7 +118,7 @@ func TestGarbageCollect(t *testing.T) { expectedDeletions: sets.NewString("backup-1"), expectedSnapshotsRemaining: sets.NewString("snapshot-3", "snapshot-4"), }, - gcTest{ + { name: "no snapshot service only GC's backups without snapshots", backups: []*api.Backup{ NewTestBackup().WithName("backup-1"). diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index bfb54d5c3..ffcf92491 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -54,7 +54,7 @@ func TestPrioritizeResources(t *testing.T) { { name: "priorities & ordering are correctly applied", apiResources: map[string][]string{ - "v1": []string{"aaa", "bbb", "configmaps", "ddd", "namespaces", "ooo", "pods", "sss"}, + "v1": {"aaa", "bbb", "configmaps", "ddd", "namespaces", "ooo", "pods", "sss"}, }, priorities: []string{"namespaces", "configmaps", "pods"}, includes: []string{"*"}, @@ -63,7 +63,7 @@ func TestPrioritizeResources(t *testing.T) { { name: "includes are correctly applied", apiResources: map[string][]string{ - "v1": []string{"aaa", "bbb", "configmaps", "ddd", "namespaces", "ooo", "pods", "sss"}, + "v1": {"aaa", "bbb", "configmaps", "ddd", "namespaces", "ooo", "pods", "sss"}, }, priorities: []string{"namespaces", "configmaps", "pods"}, includes: []string{"namespaces", "aaa", "sss"}, @@ -72,7 +72,7 @@ func TestPrioritizeResources(t *testing.T) { { name: "excludes are correctly applied", apiResources: map[string][]string{ - "v1": []string{"aaa", "bbb", "configmaps", "ddd", "namespaces", "ooo", "pods", "sss"}, + "v1": {"aaa", "bbb", "configmaps", "ddd", "namespaces", "ooo", "pods", "sss"}, }, priorities: []string{"namespaces", "configmaps", "pods"}, includes: []string{"*"}, @@ -132,8 +132,8 @@ func TestRestoreNamespaceFiltering(t *testing.T) { restore: &api.Restore{Spec: api.RestoreSpec{IncludedNamespaces: []string{"*"}}}, expectedReadDirs: []string{"bak/resources", "bak/resources/nodes/cluster", "bak/resources/secrets/namespaces", "bak/resources/secrets/namespaces/a", "bak/resources/secrets/namespaces/b", "bak/resources/secrets/namespaces/c"}, prioritizedResources: []schema.GroupResource{ - schema.GroupResource{Resource: "nodes"}, - schema.GroupResource{Resource: "secrets"}, + {Resource: "nodes"}, + {Resource: "secrets"}, }, }, { @@ -143,8 +143,8 @@ func TestRestoreNamespaceFiltering(t *testing.T) { restore: &api.Restore{Spec: api.RestoreSpec{IncludedNamespaces: []string{"b", "c"}}}, expectedReadDirs: []string{"bak/resources", "bak/resources/nodes/cluster", "bak/resources/secrets/namespaces", "bak/resources/secrets/namespaces/b", "bak/resources/secrets/namespaces/c"}, prioritizedResources: []schema.GroupResource{ - schema.GroupResource{Resource: "nodes"}, - schema.GroupResource{Resource: "secrets"}, + {Resource: "nodes"}, + {Resource: "secrets"}, }, }, { @@ -154,8 +154,8 @@ func TestRestoreNamespaceFiltering(t *testing.T) { restore: &api.Restore{Spec: api.RestoreSpec{IncludedNamespaces: []string{"*"}, ExcludedNamespaces: []string{"a"}}}, expectedReadDirs: []string{"bak/resources", "bak/resources/nodes/cluster", "bak/resources/secrets/namespaces", "bak/resources/secrets/namespaces/b", "bak/resources/secrets/namespaces/c"}, prioritizedResources: []schema.GroupResource{ - schema.GroupResource{Resource: "nodes"}, - schema.GroupResource{Resource: "secrets"}, + {Resource: "nodes"}, + {Resource: "secrets"}, }, }, { @@ -170,8 +170,8 @@ func TestRestoreNamespaceFiltering(t *testing.T) { }, expectedReadDirs: []string{"bak/resources", "bak/resources/nodes/cluster", "bak/resources/secrets/namespaces", "bak/resources/secrets/namespaces/a", "bak/resources/secrets/namespaces/c"}, prioritizedResources: []schema.GroupResource{ - schema.GroupResource{Resource: "nodes"}, - schema.GroupResource{Resource: "secrets"}, + {Resource: "nodes"}, + {Resource: "secrets"}, }, }, } @@ -217,9 +217,9 @@ func TestRestorePriority(t *testing.T) { baseDir: "bak", restore: &api.Restore{Spec: api.RestoreSpec{IncludedNamespaces: []string{"*"}}}, prioritizedResources: []schema.GroupResource{ - schema.GroupResource{Resource: "a"}, - schema.GroupResource{Resource: "b"}, - schema.GroupResource{Resource: "c"}, + {Resource: "a"}, + {Resource: "b"}, + {Resource: "c"}, }, expectedReadDirs: []string{"bak/resources", "bak/resources/a/cluster", "bak/resources/c/cluster"}, }, @@ -229,9 +229,9 @@ func TestRestorePriority(t *testing.T) { restore: &api.Restore{Spec: api.RestoreSpec{IncludedNamespaces: []string{"*"}}}, baseDir: "bak", prioritizedResources: []schema.GroupResource{ - schema.GroupResource{Resource: "c"}, - schema.GroupResource{Resource: "b"}, - schema.GroupResource{Resource: "a"}, + {Resource: "c"}, + {Resource: "b"}, + {Resource: "a"}, }, expectedReadDirs: []string{"bak/resources", "bak/resources/c/cluster", "bak/resources/a/cluster"}, }, @@ -241,9 +241,9 @@ func TestRestorePriority(t *testing.T) { restore: &api.Restore{Spec: api.RestoreSpec{IncludedNamespaces: []string{"*"}}}, baseDir: "bak", prioritizedResources: []schema.GroupResource{ - schema.GroupResource{Resource: "a"}, - schema.GroupResource{Resource: "b"}, - schema.GroupResource{Resource: "c"}, + {Resource: "a"}, + {Resource: "b"}, + {Resource: "c"}, }, expectedReadDirs: []string{"bak/resources", "bak/resources/a/namespaces", "bak/resources/a/namespaces/ns-1", "bak/resources/c/namespaces", "bak/resources/c/namespaces/ns-1"}, }, @@ -255,9 +255,9 @@ func TestRestorePriority(t *testing.T) { restore: &api.Restore{Spec: api.RestoreSpec{IncludedNamespaces: []string{"*"}}}, baseDir: "bak", prioritizedResources: []schema.GroupResource{ - schema.GroupResource{Resource: "a"}, - schema.GroupResource{Resource: "b"}, - schema.GroupResource{Resource: "c"}, + {Resource: "a"}, + {Resource: "b"}, + {Resource: "c"}, }, expectedErrors: api.RestoreResult{ Namespaces: map[string][]string{ @@ -395,7 +395,7 @@ func TestRestoreResourceForNamespace(t *testing.T) { resourcePath: "configmaps", labelSelector: labels.NewSelector(), fileSystem: newFakeFileSystem().WithFile("configmaps/cm-1.json", newTestConfigMap().ToJSON()), - restorers: map[schema.GroupResource]restorers.ResourceRestorer{schema.GroupResource{Resource: "configmaps"}: newFakeCustomRestorer()}, + restorers: map[schema.GroupResource]restorers.ResourceRestorer{{Resource: "configmaps"}: newFakeCustomRestorer()}, expectedObjs: toUnstructured(newTestConfigMap().WithLabels(map[string]string{"fake-restorer": "foo"}).WithArkLabel("my-restore").ConfigMap), }, { @@ -404,7 +404,7 @@ func TestRestoreResourceForNamespace(t *testing.T) { resourcePath: "configmaps", labelSelector: labels.NewSelector(), fileSystem: newFakeFileSystem().WithFile("configmaps/cm-1.json", newTestConfigMap().ToJSON()), - restorers: map[schema.GroupResource]restorers.ResourceRestorer{schema.GroupResource{Resource: "foo-resource"}: newFakeCustomRestorer()}, + restorers: map[schema.GroupResource]restorers.ResourceRestorer{{Resource: "foo-resource"}: newFakeCustomRestorer()}, expectedObjs: toUnstructured(newTestConfigMap().WithArkLabel("my-restore").ConfigMap), }, { diff --git a/pkg/restore/restorers/pv_restorer_test.go b/pkg/restore/restorers/pv_restorer_test.go index a16f3fb43..10fcec59a 100644 --- a/pkg/restore/restorers/pv_restorer_test.go +++ b/pkg/restore/restorers/pv_restorer_test.go @@ -75,7 +75,7 @@ func TestPVRestorerPrepare(t *testing.T) { name: "when RestorePVs=true, error if there is PV->BackupInfo map but no entry for this PV", obj: NewTestUnstructured().WithName("pv-1").WithSpecField("awsElasticBlockStore", make(map[string]interface{})).Unstructured, restore: NewDefaultTestRestore().WithRestorePVs(true).Restore, - backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"another-pv": &api.VolumeBackupInfo{}}}}, + backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"another-pv": {}}}}, expectedErr: true, }, { @@ -97,8 +97,8 @@ func TestPVRestorerPrepare(t *testing.T) { name: "when RestorePVs=true, AWS volume ID should be set correctly", obj: NewTestUnstructured().WithName("pv-1").WithSpecField("awsElasticBlockStore", make(map[string]interface{})).Unstructured, restore: NewDefaultTestRestore().WithRestorePVs(true).Restore, - backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": &api.VolumeBackupInfo{SnapshotID: "snap-1"}}}}, - volumeMap: map[api.VolumeBackupInfo]string{api.VolumeBackupInfo{SnapshotID: "snap-1"}: "volume-1"}, + backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": {SnapshotID: "snap-1"}}}}, + volumeMap: map[api.VolumeBackupInfo]string{{SnapshotID: "snap-1"}: "volume-1"}, expectedErr: false, expectedRes: NewTestUnstructured().WithName("pv-1").WithSpecField("awsElasticBlockStore", map[string]interface{}{"volumeID": "volume-1"}).Unstructured, }, @@ -106,8 +106,8 @@ func TestPVRestorerPrepare(t *testing.T) { name: "when RestorePVs=true, GCE pdName should be set correctly", obj: NewTestUnstructured().WithName("pv-1").WithSpecField("gcePersistentDisk", make(map[string]interface{})).Unstructured, restore: NewDefaultTestRestore().WithRestorePVs(true).Restore, - backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": &api.VolumeBackupInfo{SnapshotID: "snap-1"}}}}, - volumeMap: map[api.VolumeBackupInfo]string{api.VolumeBackupInfo{SnapshotID: "snap-1"}: "volume-1"}, + backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": {SnapshotID: "snap-1"}}}}, + volumeMap: map[api.VolumeBackupInfo]string{{SnapshotID: "snap-1"}: "volume-1"}, expectedErr: false, expectedRes: NewTestUnstructured().WithName("pv-1").WithSpecField("gcePersistentDisk", map[string]interface{}{"pdName": "volume-1"}).Unstructured, }, @@ -115,8 +115,8 @@ func TestPVRestorerPrepare(t *testing.T) { name: "when RestorePVs=true, Azure pdName should be set correctly", obj: NewTestUnstructured().WithName("pv-1").WithSpecField("azureDisk", make(map[string]interface{})).Unstructured, restore: NewDefaultTestRestore().WithRestorePVs(true).Restore, - backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": &api.VolumeBackupInfo{SnapshotID: "snap-1"}}}}, - volumeMap: map[api.VolumeBackupInfo]string{api.VolumeBackupInfo{SnapshotID: "snap-1"}: "volume-1"}, + backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": {SnapshotID: "snap-1"}}}}, + volumeMap: map[api.VolumeBackupInfo]string{{SnapshotID: "snap-1"}: "volume-1"}, expectedErr: false, expectedRes: NewTestUnstructured().WithName("pv-1").WithSpecField("azureDisk", map[string]interface{}{"diskName": "volume-1"}).Unstructured, }, @@ -124,8 +124,8 @@ func TestPVRestorerPrepare(t *testing.T) { name: "when RestorePVs=true, unsupported PV source should not get snapshot restored", obj: NewTestUnstructured().WithName("pv-1").WithSpecField("unsupportedPVSource", make(map[string]interface{})).Unstructured, restore: NewDefaultTestRestore().WithRestorePVs(true).Restore, - backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": &api.VolumeBackupInfo{SnapshotID: "snap-1"}}}}, - volumeMap: map[api.VolumeBackupInfo]string{api.VolumeBackupInfo{SnapshotID: "snap-1"}: "volume-1"}, + backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": {SnapshotID: "snap-1"}}}}, + volumeMap: map[api.VolumeBackupInfo]string{{SnapshotID: "snap-1"}: "volume-1"}, expectedErr: false, expectedRes: NewTestUnstructured().WithName("pv-1").WithSpecField("unsupportedPVSource", make(map[string]interface{})).Unstructured, }, @@ -133,8 +133,8 @@ func TestPVRestorerPrepare(t *testing.T) { name: "volume type and IOPS are correctly passed to CreateVolume", obj: NewTestUnstructured().WithName("pv-1").WithSpecField("awsElasticBlockStore", make(map[string]interface{})).Unstructured, restore: NewDefaultTestRestore().WithRestorePVs(true).Restore, - backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": &api.VolumeBackupInfo{SnapshotID: "snap-1", Type: "gp", Iops: &iops}}}}, - volumeMap: map[api.VolumeBackupInfo]string{api.VolumeBackupInfo{SnapshotID: "snap-1", Type: "gp", Iops: &iops}: "volume-1"}, + backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": {SnapshotID: "snap-1", Type: "gp", Iops: &iops}}}}, + volumeMap: map[api.VolumeBackupInfo]string{{SnapshotID: "snap-1", Type: "gp", Iops: &iops}: "volume-1"}, expectedErr: false, expectedRes: NewTestUnstructured().WithName("pv-1").WithSpecField("awsElasticBlockStore", map[string]interface{}{"volumeID": "volume-1"}).Unstructured, }, @@ -142,8 +142,8 @@ func TestPVRestorerPrepare(t *testing.T) { name: "When no SnapshotService, warn if backup has snapshots that will not be restored", obj: NewTestUnstructured().WithName("pv-1").WithSpecField("awsElasticBlockStore", make(map[string]interface{})).Unstructured, restore: NewDefaultTestRestore().Restore, - backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": &api.VolumeBackupInfo{SnapshotID: "snap-1"}}}}, - volumeMap: map[api.VolumeBackupInfo]string{api.VolumeBackupInfo{SnapshotID: "snap-1"}: "volume-1"}, + backup: &api.Backup{Status: api.BackupStatus{VolumeBackups: map[string]*api.VolumeBackupInfo{"pv-1": {SnapshotID: "snap-1"}}}}, + volumeMap: map[api.VolumeBackupInfo]string{{SnapshotID: "snap-1"}: "volume-1"}, noSnapshotService: true, expectedErr: false, expectedWarn: true,