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:
parent
f10c61f591
commit
0b4590b237
@ -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")
|
||||
})
|
||||
})
|
||||
|
17
internal/testutil/ioutil.go
Normal file
17
internal/testutil/ioutil.go
Normal 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 }
|
Loading…
Reference in New Issue
Block a user