testing: remove custom testingT interfaces
now that we no longer use gocheck, we should be able to just use golang's own interface. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
3e4f6225da
commit
d79cc1b67d
|
@ -3,17 +3,12 @@ package build // import "github.com/docker/docker/integration-cli/cli/build"
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/testutil/fakecontext"
|
"github.com/docker/docker/testutil/fakecontext"
|
||||||
"gotest.tools/icmd"
|
"gotest.tools/icmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testingT interface {
|
|
||||||
Fatal(args ...interface{})
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
Name() string
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithStdinContext sets the build context from the standard input with the specified reader
|
// WithStdinContext sets the build context from the standard input with the specified reader
|
||||||
func WithStdinContext(closer io.ReadCloser) func(*icmd.Cmd) func() {
|
func WithStdinContext(closer io.ReadCloser) func(*icmd.Cmd) func() {
|
||||||
return func(cmd *icmd.Cmd) func() {
|
return func(cmd *icmd.Cmd) func() {
|
||||||
|
@ -59,7 +54,7 @@ func WithExternalBuildContext(ctx *fakecontext.Fake) func(*icmd.Cmd) func() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithBuildContext sets up the build context
|
// WithBuildContext sets up the build context
|
||||||
func WithBuildContext(t testingT, contextOperators ...func(*fakecontext.Fake) error) func(*icmd.Cmd) func() {
|
func WithBuildContext(t testing.TB, contextOperators ...func(*fakecontext.Fake) error) func(*icmd.Cmd) func() {
|
||||||
// FIXME(vdemeester) de-duplicate that
|
// FIXME(vdemeester) de-duplicate that
|
||||||
ctx := fakecontext.New(t, "", contextOperators...)
|
ctx := fakecontext.New(t, "", contextOperators...)
|
||||||
return func(cmd *icmd.Cmd) func() {
|
return func(cmd *icmd.Cmd) func() {
|
||||||
|
@ -74,7 +69,7 @@ func WithFile(name, content string) func(*fakecontext.Fake) error {
|
||||||
return fakecontext.WithFile(name, content)
|
return fakecontext.WithFile(name, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func closeBuildContext(t testingT, ctx *fakecontext.Fake) func() {
|
func closeBuildContext(t testing.TB, ctx *fakecontext.Fake) func() {
|
||||||
return func() {
|
return func() {
|
||||||
if err := ctx.Close(); err != nil {
|
if err := ctx.Close(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/integration-cli/daemon"
|
"github.com/docker/docker/integration-cli/daemon"
|
||||||
"github.com/docker/docker/integration-cli/environment"
|
"github.com/docker/docker/integration-cli/environment"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gotest.tools/assert"
|
|
||||||
"gotest.tools/icmd"
|
"gotest.tools/icmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,46 +24,39 @@ func SetTestEnvironment(env *environment.Execution) {
|
||||||
// CmdOperator defines functions that can modify a command
|
// CmdOperator defines functions that can modify a command
|
||||||
type CmdOperator func(*icmd.Cmd) func()
|
type CmdOperator func(*icmd.Cmd) func()
|
||||||
|
|
||||||
type testingT interface {
|
|
||||||
assert.TestingT
|
|
||||||
Fatal(args ...interface{})
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
Name() string
|
|
||||||
}
|
|
||||||
|
|
||||||
// DockerCmd executes the specified docker command and expect a success
|
// DockerCmd executes the specified docker command and expect a success
|
||||||
func DockerCmd(t testingT, args ...string) *icmd.Result {
|
func DockerCmd(t testing.TB, args ...string) *icmd.Result {
|
||||||
return Docker(Args(args...)).Assert(t, icmd.Success)
|
return Docker(Args(args...)).Assert(t, icmd.Success)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildCmd executes the specified docker build command and expect a success
|
// BuildCmd executes the specified docker build command and expect a success
|
||||||
func BuildCmd(t testingT, name string, cmdOperators ...CmdOperator) *icmd.Result {
|
func BuildCmd(t testing.TB, name string, cmdOperators ...CmdOperator) *icmd.Result {
|
||||||
return Docker(Build(name), cmdOperators...).Assert(t, icmd.Success)
|
return Docker(Build(name), cmdOperators...).Assert(t, icmd.Success)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InspectCmd executes the specified docker inspect command and expect a success
|
// InspectCmd executes the specified docker inspect command and expect a success
|
||||||
func InspectCmd(t testingT, name string, cmdOperators ...CmdOperator) *icmd.Result {
|
func InspectCmd(t testing.TB, name string, cmdOperators ...CmdOperator) *icmd.Result {
|
||||||
return Docker(Inspect(name), cmdOperators...).Assert(t, icmd.Success)
|
return Docker(Inspect(name), cmdOperators...).Assert(t, icmd.Success)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitRun will wait for the specified container to be running, maximum 5 seconds.
|
// WaitRun will wait for the specified container to be running, maximum 5 seconds.
|
||||||
func WaitRun(t testingT, name string, cmdOperators ...CmdOperator) {
|
func WaitRun(t testing.TB, name string, cmdOperators ...CmdOperator) {
|
||||||
WaitForInspectResult(t, name, "{{.State.Running}}", "true", 5*time.Second, cmdOperators...)
|
WaitForInspectResult(t, name, "{{.State.Running}}", "true", 5*time.Second, cmdOperators...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitExited will wait for the specified container to state exit, subject
|
// WaitExited will wait for the specified container to state exit, subject
|
||||||
// to a maximum time limit in seconds supplied by the caller
|
// to a maximum time limit in seconds supplied by the caller
|
||||||
func WaitExited(t testingT, name string, timeout time.Duration, cmdOperators ...CmdOperator) {
|
func WaitExited(t testing.TB, name string, timeout time.Duration, cmdOperators ...CmdOperator) {
|
||||||
WaitForInspectResult(t, name, "{{.State.Status}}", "exited", timeout, cmdOperators...)
|
WaitForInspectResult(t, name, "{{.State.Status}}", "exited", timeout, cmdOperators...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitRestart will wait for the specified container to restart once
|
// WaitRestart will wait for the specified container to restart once
|
||||||
func WaitRestart(t testingT, name string, timeout time.Duration, cmdOperators ...CmdOperator) {
|
func WaitRestart(t testing.TB, name string, timeout time.Duration, cmdOperators ...CmdOperator) {
|
||||||
WaitForInspectResult(t, name, "{{.RestartCount}}", "1", timeout, cmdOperators...)
|
WaitForInspectResult(t, name, "{{.RestartCount}}", "1", timeout, cmdOperators...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForInspectResult waits for the specified expression to be equals to the specified expected string in the given time.
|
// WaitForInspectResult waits for the specified expression to be equals to the specified expected string in the given time.
|
||||||
func WaitForInspectResult(t testingT, name, expr, expected string, timeout time.Duration, cmdOperators ...CmdOperator) {
|
func WaitForInspectResult(t testing.TB, name, expr, expected string, timeout time.Duration, cmdOperators ...CmdOperator) {
|
||||||
after := time.After(timeout)
|
after := time.After(timeout)
|
||||||
|
|
||||||
args := []string{"inspect", "-f", expr, name}
|
args := []string{"inspect", "-f", expr, name}
|
||||||
|
|
|
@ -12,17 +12,6 @@ import (
|
||||||
"gotest.tools/icmd"
|
"gotest.tools/icmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testingT interface {
|
|
||||||
assert.TestingT
|
|
||||||
logT
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
Name() string
|
|
||||||
}
|
|
||||||
|
|
||||||
type logT interface {
|
|
||||||
Logf(string, ...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Daemon represents a Docker daemon for the testing framework.
|
// Daemon represents a Docker daemon for the testing framework.
|
||||||
type Daemon struct {
|
type Daemon struct {
|
||||||
*daemon.Daemon
|
*daemon.Daemon
|
||||||
|
@ -32,7 +21,7 @@ type Daemon struct {
|
||||||
// New returns a Daemon instance to be used for testing.
|
// New returns a Daemon instance to be used for testing.
|
||||||
// This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST.
|
// This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST.
|
||||||
// The daemon will not automatically start.
|
// The daemon will not automatically start.
|
||||||
func New(t testingT, dockerBinary string, dockerdBinary string, ops ...daemon.Option) *Daemon {
|
func New(t testing.TB, dockerBinary string, dockerdBinary string, ops ...daemon.Option) *Daemon {
|
||||||
ops = append(ops, daemon.WithDockerdBinary(dockerdBinary))
|
ops = append(ops, daemon.WithDockerdBinary(dockerdBinary))
|
||||||
d := daemon.New(t, ops...)
|
d := daemon.New(t, ops...)
|
||||||
return &Daemon{
|
return &Daemon{
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
@ -28,13 +29,6 @@ import (
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testingT interface {
|
|
||||||
assert.TestingT
|
|
||||||
logT
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
Name() string
|
|
||||||
}
|
|
||||||
|
|
||||||
type logT interface {
|
type logT interface {
|
||||||
Logf(string, ...interface{})
|
Logf(string, ...interface{})
|
||||||
}
|
}
|
||||||
|
@ -143,7 +137,7 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
|
||||||
// This will create a directory such as d123456789 in the folder specified by
|
// This will create a directory such as d123456789 in the folder specified by
|
||||||
// $DOCKER_INTEGRATION_DAEMON_DEST or $DEST.
|
// $DOCKER_INTEGRATION_DAEMON_DEST or $DEST.
|
||||||
// The daemon will not automatically start.
|
// The daemon will not automatically start.
|
||||||
func New(t testingT, ops ...Option) *Daemon {
|
func New(t testing.TB, ops ...Option) *Daemon {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -224,7 +218,7 @@ func (d *Daemon) NewClient(extraOpts ...client.Opt) (*client.Client, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup cleans the daemon files : exec root (network namespaces, ...), swarmkit files
|
// Cleanup cleans the daemon files : exec root (network namespaces, ...), swarmkit files
|
||||||
func (d *Daemon) Cleanup(t testingT) {
|
func (d *Daemon) Cleanup(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -234,7 +228,7 @@ func (d *Daemon) Cleanup(t testingT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the daemon and return once it is ready to receive requests.
|
// Start starts the daemon and return once it is ready to receive requests.
|
||||||
func (d *Daemon) Start(t testingT, args ...string) {
|
func (d *Daemon) Start(t testing.TB, args ...string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -390,7 +384,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
|
||||||
|
|
||||||
// StartWithBusybox will first start the daemon with Daemon.Start()
|
// StartWithBusybox will first start the daemon with Daemon.Start()
|
||||||
// then save the busybox image from the main daemon and load it into this Daemon instance.
|
// then save the busybox image from the main daemon and load it into this Daemon instance.
|
||||||
func (d *Daemon) StartWithBusybox(t testingT, arg ...string) {
|
func (d *Daemon) StartWithBusybox(t testing.TB, arg ...string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -449,7 +443,7 @@ func (d *Daemon) DumpStackAndQuit() {
|
||||||
// Stop will not delete the daemon directory. If a purged daemon is needed,
|
// Stop will not delete the daemon directory. If a purged daemon is needed,
|
||||||
// instantiate a new one with NewDaemon.
|
// instantiate a new one with NewDaemon.
|
||||||
// If an error occurs while starting the daemon, the test will fail.
|
// If an error occurs while starting the daemon, the test will fail.
|
||||||
func (d *Daemon) Stop(t testingT) {
|
func (d *Daemon) Stop(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -537,7 +531,7 @@ out2:
|
||||||
|
|
||||||
// Restart will restart the daemon by first stopping it and the starting it.
|
// Restart will restart the daemon by first stopping it and the starting it.
|
||||||
// If an error occurs while starting the daemon, the test will fail.
|
// If an error occurs while starting the daemon, the test will fail.
|
||||||
func (d *Daemon) Restart(t testingT, args ...string) {
|
func (d *Daemon) Restart(t testing.TB, args ...string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -737,7 +731,7 @@ func (d *Daemon) Info(t assert.TestingT) types.Info {
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupRaftDir(t testingT, rootPath string) {
|
func cleanupRaftDir(t testing.TB, rootPath string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,14 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/testutil"
|
"github.com/docker/docker/testutil"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cleanupNetworkNamespace(t testingT, execRoot string) {
|
func cleanupNetworkNamespace(t testing.TB, execRoot string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -33,7 +34,7 @@ func cleanupNetworkNamespace(t testingT, execRoot string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CgroupNamespace returns the cgroup namespace the daemon is running in
|
// CgroupNamespace returns the cgroup namespace the daemon is running in
|
||||||
func (d *Daemon) CgroupNamespace(t assert.TestingT) string {
|
func (d *Daemon) CgroupNamespace(t testing.TB) string {
|
||||||
link, err := os.Readlink(fmt.Sprintf("/proc/%d/ns/cgroup", d.Pid()))
|
link, err := os.Readlink(fmt.Sprintf("/proc/%d/ns/cgroup", d.Pid()))
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package daemon
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
|
@ -22,11 +23,11 @@ func signalDaemonReload(pid int) error {
|
||||||
return fmt.Errorf("daemon reload not supported")
|
return fmt.Errorf("daemon reload not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupNetworkNamespace(t testingT, execRoot string) {
|
func cleanupNetworkNamespace(t testing.TB, execRoot string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CgroupNamespace returns the cgroup namespace the daemon is running in
|
// CgroupNamespace returns the cgroup namespace the daemon is running in
|
||||||
func (d *Daemon) CgroupNamespace(t assert.TestingT) string {
|
func (d *Daemon) CgroupNamespace(t testing.TB) string {
|
||||||
assert.Assert(t, false)
|
assert.Assert(t, false)
|
||||||
return "cgroup namespaces are not supported on Windows"
|
return "cgroup namespaces are not supported on Windows"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package daemon
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/testutil"
|
"github.com/docker/docker/testutil"
|
||||||
|
@ -21,7 +22,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// StartNode (re)starts the daemon
|
// StartNode (re)starts the daemon
|
||||||
func (d *Daemon) StartNode(t testingT) {
|
func (d *Daemon) StartNode(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -29,7 +30,7 @@ func (d *Daemon) StartNode(t testingT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartNodeWithBusybox starts daemon to be used as a swarm node, and loads the busybox image
|
// StartNodeWithBusybox starts daemon to be used as a swarm node, and loads the busybox image
|
||||||
func (d *Daemon) StartNodeWithBusybox(t testingT) {
|
func (d *Daemon) StartNodeWithBusybox(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -37,7 +38,7 @@ func (d *Daemon) StartNodeWithBusybox(t testingT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RestartNode restarts a daemon to be used as a swarm node
|
// RestartNode restarts a daemon to be used as a swarm node
|
||||||
func (d *Daemon) RestartNode(t testingT) {
|
func (d *Daemon) RestartNode(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -47,13 +48,13 @@ func (d *Daemon) RestartNode(t testingT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartAndSwarmInit starts the daemon (with busybox) and init the swarm
|
// StartAndSwarmInit starts the daemon (with busybox) and init the swarm
|
||||||
func (d *Daemon) StartAndSwarmInit(t testingT) {
|
func (d *Daemon) StartAndSwarmInit(t testing.TB) {
|
||||||
d.StartNodeWithBusybox(t)
|
d.StartNodeWithBusybox(t)
|
||||||
d.SwarmInit(t, swarm.InitRequest{})
|
d.SwarmInit(t, swarm.InitRequest{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartAndSwarmJoin starts the daemon (with busybox) and join the specified swarm as worker or manager
|
// StartAndSwarmJoin starts the daemon (with busybox) and join the specified swarm as worker or manager
|
||||||
func (d *Daemon) StartAndSwarmJoin(t testingT, leader *Daemon, manager bool) {
|
func (d *Daemon) StartAndSwarmJoin(t testing.TB, leader *Daemon, manager bool) {
|
||||||
if th, ok := t.(testutil.HelperT); ok {
|
if th, ok := t.(testutil.HelperT); ok {
|
||||||
th.Helper()
|
th.Helper()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,19 +6,14 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/testutil"
|
"github.com/docker/docker/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testingT interface {
|
|
||||||
Fatal(args ...interface{})
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
Name() string
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates a fake build context
|
// New creates a fake build context
|
||||||
func New(t testingT, dir string, modifiers ...func(*Fake) error) *Fake {
|
func New(t testing.TB, dir string, modifiers ...func(*Fake) error) *Fake {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -120,7 +115,7 @@ func (f *Fake) Close() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsTarReader returns a ReadCloser with the contents of Dir as a tar archive.
|
// AsTarReader returns a ReadCloser with the contents of Dir as a tar archive.
|
||||||
func (f *Fake) AsTarReader(t testingT) io.ReadCloser {
|
func (f *Fake) AsTarReader(t testing.TB) io.ReadCloser {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,30 +8,13 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/testutil"
|
"github.com/docker/docker/testutil"
|
||||||
"github.com/docker/docker/testutil/fakecontext"
|
"github.com/docker/docker/testutil/fakecontext"
|
||||||
"github.com/docker/docker/testutil/fakestorage"
|
"github.com/docker/docker/testutil/fakestorage"
|
||||||
"gotest.tools/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type testingT interface {
|
|
||||||
assert.TestingT
|
|
||||||
logT
|
|
||||||
skipT
|
|
||||||
Fatal(args ...interface{})
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
Name() string
|
|
||||||
}
|
|
||||||
|
|
||||||
type logT interface {
|
|
||||||
Logf(string, ...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type skipT interface {
|
|
||||||
Skip(...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type gitServer interface {
|
type gitServer interface {
|
||||||
URL() string
|
URL() string
|
||||||
Close() error
|
Close() error
|
||||||
|
@ -64,7 +47,7 @@ func (g *FakeGit) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New create a fake git server that can be used for git related tests
|
// New create a fake git server that can be used for git related tests
|
||||||
func New(c testingT, name string, files map[string]string, enforceLocalServer bool) *FakeGit {
|
func New(c testing.TB, name string, files map[string]string, enforceLocalServer bool) *FakeGit {
|
||||||
if ht, ok := c.(testutil.HelperT); ok {
|
if ht, ok := c.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
|
@ -17,7 +18,7 @@ import (
|
||||||
|
|
||||||
var ensureHTTPServerOnce sync.Once
|
var ensureHTTPServerOnce sync.Once
|
||||||
|
|
||||||
func ensureHTTPServerImage(t testingT) {
|
func ensureHTTPServerImage(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
containertypes "github.com/docker/docker/api/types/container"
|
containertypes "github.com/docker/docker/api/types/container"
|
||||||
|
@ -24,23 +25,6 @@ import (
|
||||||
|
|
||||||
var testEnv *environment.Execution
|
var testEnv *environment.Execution
|
||||||
|
|
||||||
type testingT interface {
|
|
||||||
assert.TestingT
|
|
||||||
logT
|
|
||||||
skipT
|
|
||||||
Fatal(args ...interface{})
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
Name() string
|
|
||||||
}
|
|
||||||
|
|
||||||
type logT interface {
|
|
||||||
Logf(string, ...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type skipT interface {
|
|
||||||
Skip(...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fake is a static file server. It might be running locally or remotely
|
// Fake is a static file server. It might be running locally or remotely
|
||||||
// on test host.
|
// on test host.
|
||||||
type Fake interface {
|
type Fake interface {
|
||||||
|
@ -56,7 +40,7 @@ func SetTestEnvironment(env *environment.Execution) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a static file server that will be use as build context.
|
// New returns a static file server that will be use as build context.
|
||||||
func New(t testingT, dir string, modifiers ...func(*fakecontext.Fake) error) Fake {
|
func New(t testing.TB, dir string, modifiers ...func(*fakecontext.Fake) error) Fake {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -149,7 +133,7 @@ func (f *remoteFileServer) Close() error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRemoteFileServer(t testingT, ctx *fakecontext.Fake, c client.APIClient) *remoteFileServer {
|
func newRemoteFileServer(t testing.TB, ctx *fakecontext.Fake, c client.APIClient) *remoteFileServer {
|
||||||
var (
|
var (
|
||||||
image = fmt.Sprintf("fileserver-img-%s", strings.ToLower(testutil.GenerateRandomAlphaOnlyString(10)))
|
image = fmt.Sprintf("fileserver-img-%s", strings.ToLower(testutil.GenerateRandomAlphaOnlyString(10)))
|
||||||
container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(testutil.GenerateRandomAlphaOnlyString(10)))
|
container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(testutil.GenerateRandomAlphaOnlyString(10)))
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/testutil"
|
"github.com/docker/docker/testutil"
|
||||||
|
@ -23,18 +24,6 @@ const (
|
||||||
DefaultURL = "127.0.0.1:5000"
|
DefaultURL = "127.0.0.1:5000"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testingT interface {
|
|
||||||
assert.TestingT
|
|
||||||
logT
|
|
||||||
Fatal(...interface{})
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
Name() string
|
|
||||||
}
|
|
||||||
|
|
||||||
type logT interface {
|
|
||||||
Logf(string, ...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// V2 represent a registry version 2
|
// V2 represent a registry version 2
|
||||||
type V2 struct {
|
type V2 struct {
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
|
@ -55,7 +44,7 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewV2 creates a v2 registry server
|
// NewV2 creates a v2 registry server
|
||||||
func NewV2(t testingT, ops ...func(*Config)) *V2 {
|
func NewV2(t testing.TB, ops ...func(*Config)) *V2 {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -140,7 +129,7 @@ http:
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitReady waits for the registry to be ready to serve requests (or fail after a while)
|
// WaitReady waits for the registry to be ready to serve requests (or fail after a while)
|
||||||
func (r *V2) WaitReady(t testingT) {
|
func (r *V2) WaitReady(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
@ -212,7 +201,7 @@ func (r *V2) WriteBlobContents(t assert.TestingT, blobDigest digest.Digest, data
|
||||||
|
|
||||||
// TempMoveBlobData moves the existing data file aside, so that we can replace it with a
|
// TempMoveBlobData moves the existing data file aside, so that we can replace it with a
|
||||||
// malicious blob of data for example.
|
// malicious blob of data for example.
|
||||||
func (r *V2) TempMoveBlobData(t testingT, blobDigest digest.Digest) (undo func()) {
|
func (r *V2) TempMoveBlobData(t testing.TB, blobDigest digest.Digest) (undo func()) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/testutil"
|
"github.com/docker/docker/testutil"
|
||||||
)
|
)
|
||||||
|
@ -28,7 +29,7 @@ func (tr *Mock) RegisterHandler(path string, h handlerFunc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMock creates a registry mock
|
// NewMock creates a registry mock
|
||||||
func NewMock(t testingT) (*Mock, error) {
|
func NewMock(t testing.TB) (*Mock, error) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
if ht, ok := t.(testutil.HelperT); ok {
|
||||||
ht.Helper()
|
ht.Helper()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue