diff --git a/cmd/placeholder-name/main_test.go b/cmd/placeholder-name/main_test.go index 871119b6..1276d6fd 100644 --- a/cmd/placeholder-name/main_test.go +++ b/cmd/placeholder-name/main_test.go @@ -16,12 +16,10 @@ import ( "github.com/sclevine/spec/report" "github.com/stretchr/testify/require" "k8s.io/client-go/pkg/apis/clientauthentication" + + "github.com/suzerain-io/placeholder-name/test/library" ) -type errWriter struct{ returnErr error } - -func (e *errWriter) Write([]byte) (int, error) { return 0, e.returnErr } - func TestRun(t *testing.T) { spec.Run(t, "Run", func(t *testing.T, when spec.G, it spec.S) { var buffer *bytes.Buffer @@ -97,7 +95,7 @@ func TestRun(t *testing.T) { }) it("returns an error", func() { - err := run(envGetter, tokenExchanger, &errWriter{returnErr: fmt.Errorf("some IO error")}, 30*time.Second) + err := run(envGetter, tokenExchanger, &library.ErrorWriter{ReturnError: fmt.Errorf("some IO error")}, 30*time.Second) require.EqualError(t, err, "failed to marshal response to stdout: some IO error") }) }, spec.Parallel()) diff --git a/test/library/ioutil.go b/test/library/ioutil.go new file mode 100644 index 00000000..44bf24ca --- /dev/null +++ b/test/library/ioutil.go @@ -0,0 +1,17 @@ +/* +Copyright 2020 VMware, Inc. +SPDX-License-Identifier: Apache-2.0 +*/ + +package library + +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 }