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:
parent
dd278b46a8
commit
31e6d8fbb1
@ -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
2
go.mod
@ -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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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 }
|
|
Loading…
Reference in New Issue
Block a user