From f6f2789e3c08b2d37ae300e66c1b56f348f285b4 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Thu, 5 Oct 2017 20:06:55 -0700 Subject: [PATCH] fix tests Signed-off-by: Steve Kriss --- pkg/backup/backup_test.go | 23 ++++++++++++++++------- pkg/backup/volume_snapshot_action_test.go | 6 ++++-- pkg/restore/restore_test.go | 14 ++++++++++---- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/pkg/backup/backup_test.go b/pkg/backup/backup_test.go index 89056349356..abfc306f17a 100644 --- a/pkg/backup/backup_test.go +++ b/pkg/backup/backup_test.go @@ -29,6 +29,11 @@ import ( "testing" "time" + testlogger "github.com/sirupsen/logrus/hooks/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -39,9 +44,6 @@ import ( "github.com/heptio/ark/pkg/apis/ark/v1" "github.com/heptio/ark/pkg/util/collections" . "github.com/heptio/ark/pkg/util/test" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" ) type fakeAction struct { @@ -189,9 +191,10 @@ func TestGetResourceIncludesExcludes(t *testing.T) { }, } - b := new(bytes.Buffer) + log, _ := testlogger.NewNullLogger() + ctx := &backupContext{ - logger: &logger{w: b}, + logger: &logger{impl: log}, } actual := ctx.getResourceIncludesExcludes(dh, test.includes, test.excludes) @@ -758,6 +761,9 @@ func TestBackupResource(t *testing.T) { require.NoError(t, err) labelSelector = s } + + log, _ := testlogger.NewNullLogger() + ctx := &backupContext{ backup: &v1.Backup{ Spec: v1.BackupSpec{ @@ -768,7 +774,7 @@ func TestBackupResource(t *testing.T) { namespaceIncludesExcludes: test.namespaceIncludesExcludes, deploymentsBackedUp: test.deploymentsBackedUp, networkPoliciesBackedUp: test.networkPoliciesBackedUp, - logger: &logger{w: new(bytes.Buffer)}, + logger: &logger{impl: log}, } group := &metav1.APIResourceList{ @@ -992,11 +998,14 @@ func TestBackupItem(t *testing.T) { actionParam = action backup = &v1.Backup{} } + + log, _ := testlogger.NewNullLogger() + ctx := &backupContext{ backup: backup, namespaceIncludesExcludes: namespaces, w: w, - logger: &logger{w: new(bytes.Buffer)}, + logger: &logger{impl: log}, } b := &realItemBackupper{} err = b.backupItem(ctx, item, "resource.group", actionParam) diff --git a/pkg/backup/volume_snapshot_action_test.go b/pkg/backup/volume_snapshot_action_test.go index e524a59557b..063db351a85 100644 --- a/pkg/backup/volume_snapshot_action_test.go +++ b/pkg/backup/volume_snapshot_action_test.go @@ -17,11 +17,11 @@ limitations under the License. package backup import ( - "bytes" "reflect" "testing" "time" + testlogger "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -186,7 +186,9 @@ func TestVolumeSnapshotAction(t *testing.T) { t.Fatal(err) } - actionCtx := ActionContext{logger: &logger{w: new(bytes.Buffer)}} + log, _ := testlogger.NewNullLogger() + + actionCtx := ActionContext{logger: &logger{impl: log}} err = action.Execute(actionCtx, pv, backup) gotErr := err != nil diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index 09eaab7d0be..c493d590e7b 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -19,11 +19,11 @@ package restore import ( "encoding/json" "io" - "io/ioutil" "os" "testing" "github.com/sirupsen/logrus/hooks/test" + testlogger "github.com/sirupsen/logrus/hooks/test" "github.com/spf13/afero" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -174,11 +174,13 @@ func TestRestoreMethod(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { + log, _ := testlogger.NewNullLogger() + ctx := &context{ restore: test.restore, namespaceClient: &fakeNamespaceClient{}, fileSystem: test.fileSystem, - logger: &logger{w: ioutil.Discard}, + logger: &logger{impl: log}, } warnings, errors := ctx.restoreFromDir(test.baseDir) @@ -266,12 +268,14 @@ func TestRestoreNamespace(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { + log, _ := testlogger.NewNullLogger() + ctx := &context{ restore: test.restore, namespaceClient: &fakeNamespaceClient{}, fileSystem: test.fileSystem, prioritizedResources: test.prioritizedResources, - logger: &logger{w: ioutil.Discard}, + logger: &logger{impl: log}, } warnings, errors := ctx.restoreNamespace(test.namespace, test.path) @@ -407,6 +411,8 @@ func TestRestoreResourceForNamespace(t *testing.T) { gvk := schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"} dynamicFactory.On("ClientForGroupVersionKind", gvk, resource, test.namespace).Return(resourceClient, nil) + log, _ := testlogger.NewNullLogger() + ctx := &context{ dynamicFactory: dynamicFactory, restorers: test.restorers, @@ -419,7 +425,7 @@ func TestRestoreResourceForNamespace(t *testing.T) { }, }, backup: &api.Backup{}, - logger: &logger{w: ioutil.Discard}, + logger: &logger{impl: log}, } warnings, errors := ctx.restoreResourceForNamespace(test.namespace, test.resourcePath)