Drop main module dependency on test module

I suppose we could solve this other ways, but this utility was
only used in one place right now, so it is easiest to copy it over.

Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
Andrew Keesler 2020-08-06 10:29:04 -04:00
parent dd278b46a8
commit 31e6d8fbb1
No known key found for this signature in database
GPG Key ID: 27CE0444346F9413
3 changed files with 11 additions and 21 deletions

View File

@ -9,6 +9,7 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"io"
"testing" "testing"
"time" "time"
@ -17,9 +18,17 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/suzerain-io/placeholder-name/pkg/client" "github.com/suzerain-io/placeholder-name/pkg/client"
"github.com/suzerain-io/placeholder-name/test/library"
) )
// 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) { func TestRun(t *testing.T) {
spec.Run(t, "main.run", func(t *testing.T, when spec.G, it spec.S) { spec.Run(t, "main.run", func(t *testing.T, when spec.G, it spec.S) {
var r *require.Assertions var r *require.Assertions
@ -86,7 +95,7 @@ func TestRun(t *testing.T) {
}) })
it("returns an error", func() { it("returns an error", func() {
err := run(envGetter, tokenExchanger, &library.ErrorWriter{ReturnError: fmt.Errorf("some IO error")}, 30*time.Second) err := run(envGetter, tokenExchanger, &errorWriter{returnError: fmt.Errorf("some IO error")}, 30*time.Second)
r.EqualError(err, "failed to marshal response to stdout: some IO error") r.EqualError(err, "failed to marshal response to stdout: some IO error")
}) })
}) })

2
go.mod
View File

@ -3,7 +3,6 @@ module github.com/suzerain-io/placeholder-name
go 1.14 go 1.14
require ( require (
github.com/davecgh/go-spew v1.1.1
github.com/golang/mock v1.4.3 github.com/golang/mock v1.4.3
github.com/golangci/golangci-lint v1.29.0 github.com/golangci/golangci-lint v1.29.0
github.com/google/go-cmp v0.5.0 github.com/google/go-cmp v0.5.0
@ -21,7 +20,6 @@ require (
k8s.io/component-base v0.19.0-rc.0 k8s.io/component-base v0.19.0-rc.0
k8s.io/klog/v2 v2.2.0 k8s.io/klog/v2 v2.2.0
k8s.io/kube-aggregator v0.19.0-rc.0 k8s.io/kube-aggregator v0.19.0-rc.0
k8s.io/utils v0.0.0-20200619165400-6e3d28b6ed19
sigs.k8s.io/yaml v1.2.0 sigs.k8s.io/yaml v1.2.0
) )

View File

@ -1,17 +0,0 @@
/*
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 }