Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <[email protected]>
  • Loading branch information
skriss committed Oct 6, 2017
1 parent be45b8b commit f6f2789
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
23 changes: 16 additions & 7 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions pkg/backup/volume_snapshot_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
14 changes: 10 additions & 4 deletions pkg/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit f6f2789

Please sign in to comment.