Now that we have a testutil package, put ioutil.go into it

Signed-off-by: Ryan Richard <richardry@vmware.com>
This commit is contained in:
Andrew Keesler 2020-08-06 15:19:09 -07:00 committed by Ryan Richard
parent f10c61f591
commit 0b4590b237
2 changed files with 20 additions and 11 deletions

View File

@ -9,10 +9,11 @@ import (
"bytes"
"context"
"fmt"
"io"
"testing"
"time"
"github.com/suzerain-io/placeholder-name/internal/testutil"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/stretchr/testify/require"
@ -20,15 +21,6 @@ import (
"github.com/suzerain-io/placeholder-name/pkg/client"
)
// errorWriter implements io.Writer by returning a fixed error.
type errorWriter struct {
returnError error
}
var _ io.Writer = &errorWriter{}
func (e *errorWriter) Write([]byte) (int, error) { return 0, e.returnError }
func TestRun(t *testing.T) {
spec.Run(t, "main.run", func(t *testing.T, when spec.G, it spec.S) {
var r *require.Assertions
@ -95,7 +87,7 @@ func TestRun(t *testing.T) {
})
it("returns an error", func() {
err := run(envGetter, tokenExchanger, &errorWriter{returnError: fmt.Errorf("some IO error")}, 30*time.Second)
err := run(envGetter, tokenExchanger, &testutil.ErrorWriter{ReturnError: fmt.Errorf("some IO error")}, 30*time.Second)
r.EqualError(err, "failed to marshal response to stdout: some IO error")
})
})

View File

@ -0,0 +1,17 @@
/*
Copyright 2020 VMware, Inc.
SPDX-License-Identifier: Apache-2.0
*/
package testutil
import "io"
// ErrorWriter implements io.Writer by returning a fixed error.
type ErrorWriter struct {
ReturnError error
}
var _ io.Writer = &ErrorWriter{}
func (e *ErrorWriter) Write([]byte) (int, error) { return 0, e.ReturnError }