Remove some uses of testutil.HelperT
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d79cc1b67d
commit
0d4ffa3588
9 changed files with 21 additions and 69 deletions
|
@ -138,9 +138,7 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
|
||||||
// $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 testing.TB, ops ...Option) *Daemon {
|
func New(t testing.TB, ops ...Option) *Daemon {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
dest := os.Getenv("DOCKER_INTEGRATION_DAEMON_DEST")
|
dest := os.Getenv("DOCKER_INTEGRATION_DAEMON_DEST")
|
||||||
if dest == "" {
|
if dest == "" {
|
||||||
dest = os.Getenv("DEST")
|
dest = os.Getenv("DEST")
|
||||||
|
@ -219,9 +217,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 testing.TB) {
|
func (d *Daemon) Cleanup(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
// Cleanup swarmkit wal files if present
|
// Cleanup swarmkit wal files if present
|
||||||
cleanupRaftDir(t, d.Root)
|
cleanupRaftDir(t, d.Root)
|
||||||
cleanupNetworkNamespace(t, d.execRoot)
|
cleanupNetworkNamespace(t, d.execRoot)
|
||||||
|
@ -229,9 +225,7 @@ func (d *Daemon) Cleanup(t testing.TB) {
|
||||||
|
|
||||||
// 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 testing.TB, args ...string) {
|
func (d *Daemon) Start(t testing.TB, args ...string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
if err := d.StartWithError(args...); err != nil {
|
if err := d.StartWithError(args...); err != nil {
|
||||||
t.Fatalf("failed to start daemon with arguments %v : %v", args, err)
|
t.Fatalf("failed to start daemon with arguments %v : %v", args, err)
|
||||||
}
|
}
|
||||||
|
@ -385,9 +379,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 testing.TB, arg ...string) {
|
func (d *Daemon) StartWithBusybox(t testing.TB, arg ...string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
d.Start(t, arg...)
|
d.Start(t, arg...)
|
||||||
d.LoadBusybox(t)
|
d.LoadBusybox(t)
|
||||||
}
|
}
|
||||||
|
@ -444,9 +436,7 @@ func (d *Daemon) DumpStackAndQuit() {
|
||||||
// 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 testing.TB) {
|
func (d *Daemon) Stop(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
err := d.StopWithError()
|
err := d.StopWithError()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != errDaemonNotStarted {
|
if err != errDaemonNotStarted {
|
||||||
|
@ -532,9 +522,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 testing.TB, args ...string) {
|
func (d *Daemon) Restart(t testing.TB, args ...string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
d.Stop(t)
|
d.Stop(t)
|
||||||
d.Start(t, args...)
|
d.Start(t, args...)
|
||||||
}
|
}
|
||||||
|
@ -732,9 +720,7 @@ func (d *Daemon) Info(t assert.TestingT) types.Info {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupRaftDir(t testing.TB, rootPath string) {
|
func cleanupRaftDir(t testing.TB, rootPath string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
for _, p := range []string{"wal", "wal-v3-encrypted", "snap-v3-encrypted"} {
|
for _, p := range []string{"wal", "wal-v3-encrypted", "snap-v3-encrypted"} {
|
||||||
dir := filepath.Join(rootPath, "swarm/raft", p)
|
dir := filepath.Join(rootPath, "swarm/raft", p)
|
||||||
if err := os.RemoveAll(dir); err != nil {
|
if err := os.RemoveAll(dir); err != nil {
|
||||||
|
|
|
@ -9,15 +9,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/testutil"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cleanupNetworkNamespace(t testing.TB, execRoot string) {
|
func cleanupNetworkNamespace(t testing.TB, execRoot string) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
// Cleanup network namespaces in the exec root of this
|
// Cleanup network namespaces in the exec root of this
|
||||||
// daemon because this exec root is specific to this
|
// daemon because this exec root is specific to this
|
||||||
// daemon instance and has no chance of getting
|
// daemon instance and has no chance of getting
|
||||||
|
|
|
@ -23,25 +23,19 @@ var (
|
||||||
|
|
||||||
// StartNode (re)starts the daemon
|
// StartNode (re)starts the daemon
|
||||||
func (d *Daemon) StartNode(t testing.TB) {
|
func (d *Daemon) StartNode(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
d.Start(t, startArgs...)
|
d.Start(t, startArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 testing.TB) {
|
func (d *Daemon) StartNodeWithBusybox(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
d.StartWithBusybox(t, startArgs...)
|
d.StartWithBusybox(t, startArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 testing.TB) {
|
func (d *Daemon) RestartNode(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
// avoid networking conflicts
|
// avoid networking conflicts
|
||||||
d.Stop(t)
|
d.Stop(t)
|
||||||
d.Start(t, startArgs...)
|
d.Start(t, startArgs...)
|
||||||
|
@ -55,9 +49,7 @@ func (d *Daemon) StartAndSwarmInit(t testing.TB) {
|
||||||
|
|
||||||
// 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 testing.TB, leader *Daemon, manager bool) {
|
func (d *Daemon) StartAndSwarmJoin(t testing.TB, leader *Daemon, manager bool) {
|
||||||
if th, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
th.Helper()
|
|
||||||
}
|
|
||||||
d.StartNodeWithBusybox(t)
|
d.StartNodeWithBusybox(t)
|
||||||
|
|
||||||
tokens := leader.JoinTokens(t)
|
tokens := leader.JoinTokens(t)
|
||||||
|
|
|
@ -9,14 +9,11 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/testutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates a fake build context
|
// New creates a fake build context
|
||||||
func New(t testing.TB, 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 {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
fakeContext := &Fake{Dir: dir}
|
fakeContext := &Fake{Dir: dir}
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
if err := newDir(fakeContext); err != nil {
|
if err := newDir(fakeContext); err != nil {
|
||||||
|
@ -116,9 +113,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 testing.TB) io.ReadCloser {
|
func (f *Fake) AsTarReader(t testing.TB) io.ReadCloser {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
reader, err := archive.TarWithOptions(f.Dir, &archive.TarOptions{})
|
reader, err := archive.TarWithOptions(f.Dir, &archive.TarOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create tar from %s: %s", f.Dir, err)
|
t.Fatalf("Failed to create tar from %s: %s", f.Dir, err)
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
@ -48,9 +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 testing.TB, 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 {
|
c.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
ctx := fakecontext.New(c, "", fakecontext.WithFiles(files))
|
ctx := fakecontext.New(c, "", fakecontext.WithFiles(files))
|
||||||
defer ctx.Close()
|
defer ctx.Close()
|
||||||
curdir, err := os.Getwd()
|
curdir, err := os.Getwd()
|
||||||
|
|
|
@ -12,16 +12,13 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/testutil"
|
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ensureHTTPServerOnce sync.Once
|
var ensureHTTPServerOnce sync.Once
|
||||||
|
|
||||||
func ensureHTTPServerImage(t testing.TB) {
|
func ensureHTTPServerImage(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
var doIt bool
|
var doIt bool
|
||||||
ensureHTTPServerOnce.Do(func() {
|
ensureHTTPServerOnce.Do(func() {
|
||||||
doIt = true
|
doIt = true
|
||||||
|
|
|
@ -41,9 +41,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 testing.TB, 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 {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
if testEnv == nil {
|
if testEnv == nil {
|
||||||
t.Fatal("fakstorage package requires SetTestEnvironment() to be called before use.")
|
t.Fatal("fakstorage package requires SetTestEnvironment() to be called before use.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,7 @@ type Config struct {
|
||||||
|
|
||||||
// NewV2 creates a v2 registry server
|
// NewV2 creates a v2 registry server
|
||||||
func NewV2(t testing.TB, ops ...func(*Config)) *V2 {
|
func NewV2(t testing.TB, ops ...func(*Config)) *V2 {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
c := &Config{
|
c := &Config{
|
||||||
registryURL: DefaultURL,
|
registryURL: DefaultURL,
|
||||||
}
|
}
|
||||||
|
@ -130,9 +128,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 testing.TB) {
|
func (r *V2) WaitReady(t testing.TB) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
var err error
|
var err error
|
||||||
for i := 0; i != 50; i++ {
|
for i := 0; i != 50; i++ {
|
||||||
if err = r.Ping(); err == nil {
|
if err = r.Ping(); err == nil {
|
||||||
|
@ -202,9 +198,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 testing.TB, blobDigest digest.Digest) (undo func()) {
|
func (r *V2) TempMoveBlobData(t testing.TB, blobDigest digest.Digest) (undo func()) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
tempFile, err := ioutil.TempFile("", "registry-temp-blob-")
|
tempFile, err := ioutil.TempFile("", "registry-temp-blob-")
|
||||||
assert.NilError(t, err, "unable to get temporary blob file")
|
assert.NilError(t, err, "unable to get temporary blob file")
|
||||||
tempFile.Close()
|
tempFile.Close()
|
||||||
|
|
|
@ -7,8 +7,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/testutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type handlerFunc func(w http.ResponseWriter, r *http.Request)
|
type handlerFunc func(w http.ResponseWriter, r *http.Request)
|
||||||
|
@ -30,9 +28,7 @@ func (tr *Mock) RegisterHandler(path string, h handlerFunc) {
|
||||||
|
|
||||||
// NewMock creates a registry mock
|
// NewMock creates a registry mock
|
||||||
func NewMock(t testing.TB) (*Mock, error) {
|
func NewMock(t testing.TB) (*Mock, error) {
|
||||||
if ht, ok := t.(testutil.HelperT); ok {
|
t.Helper()
|
||||||
ht.Helper()
|
|
||||||
}
|
|
||||||
testReg := &Mock{handlers: make(map[string]handlerFunc)}
|
testReg := &Mock{handlers: make(map[string]handlerFunc)}
|
||||||
|
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
Loading…
Reference in a new issue