Remove some uses of testutil.HelperT

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-09-23 14:06:27 +02:00
parent d79cc1b67d
commit 0d4ffa3588
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
9 changed files with 21 additions and 69 deletions

View file

@ -138,9 +138,7 @@ func NewDaemon(workingDir string, ops ...Option) (*Daemon, error) {
// $DOCKER_INTEGRATION_DAEMON_DEST or $DEST.
// The daemon will not automatically start.
func New(t testing.TB, ops ...Option) *Daemon {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
dest := os.Getenv("DOCKER_INTEGRATION_DAEMON_DEST")
if 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
func (d *Daemon) Cleanup(t testing.TB) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
// Cleanup swarmkit wal files if present
cleanupRaftDir(t, d.Root)
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.
func (d *Daemon) Start(t testing.TB, args ...string) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
if err := d.StartWithError(args...); err != nil {
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()
// 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) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
d.Start(t, arg...)
d.LoadBusybox(t)
}
@ -444,9 +436,7 @@ func (d *Daemon) DumpStackAndQuit() {
// instantiate a new one with NewDaemon.
// If an error occurs while starting the daemon, the test will fail.
func (d *Daemon) Stop(t testing.TB) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
err := d.StopWithError()
if err != nil {
if err != errDaemonNotStarted {
@ -532,9 +522,7 @@ out2:
// 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.
func (d *Daemon) Restart(t testing.TB, args ...string) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
d.Stop(t)
d.Start(t, args...)
}
@ -732,9 +720,7 @@ func (d *Daemon) Info(t assert.TestingT) types.Info {
}
func cleanupRaftDir(t testing.TB, rootPath string) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
for _, p := range []string{"wal", "wal-v3-encrypted", "snap-v3-encrypted"} {
dir := filepath.Join(rootPath, "swarm/raft", p)
if err := os.RemoveAll(dir); err != nil {

View file

@ -9,15 +9,12 @@ import (
"strings"
"testing"
"github.com/docker/docker/testutil"
"golang.org/x/sys/unix"
"gotest.tools/assert"
)
func cleanupNetworkNamespace(t testing.TB, execRoot string) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
// Cleanup network namespaces in the exec root of this
// daemon because this exec root is specific to this
// daemon instance and has no chance of getting

View file

@ -23,25 +23,19 @@ var (
// StartNode (re)starts the daemon
func (d *Daemon) StartNode(t testing.TB) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
d.Start(t, startArgs...)
}
// StartNodeWithBusybox starts daemon to be used as a swarm node, and loads the busybox image
func (d *Daemon) StartNodeWithBusybox(t testing.TB) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
d.StartWithBusybox(t, startArgs...)
}
// RestartNode restarts a daemon to be used as a swarm node
func (d *Daemon) RestartNode(t testing.TB) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
// avoid networking conflicts
d.Stop(t)
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
func (d *Daemon) StartAndSwarmJoin(t testing.TB, leader *Daemon, manager bool) {
if th, ok := t.(testutil.HelperT); ok {
th.Helper()
}
t.Helper()
d.StartNodeWithBusybox(t)
tokens := leader.JoinTokens(t)

View file

@ -9,14 +9,11 @@ import (
"testing"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/testutil"
)
// New creates a fake build context
func New(t testing.TB, dir string, modifiers ...func(*Fake) error) *Fake {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
fakeContext := &Fake{Dir: dir}
if dir == "" {
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.
func (f *Fake) AsTarReader(t testing.TB) io.ReadCloser {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
reader, err := archive.TarWithOptions(f.Dir, &archive.TarOptions{})
if err != nil {
t.Fatalf("Failed to create tar from %s: %s", f.Dir, err)

View file

@ -10,7 +10,6 @@ import (
"path/filepath"
"testing"
"github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/fakecontext"
"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
func New(c testing.TB, name string, files map[string]string, enforceLocalServer bool) *FakeGit {
if ht, ok := c.(testutil.HelperT); ok {
ht.Helper()
}
c.Helper()
ctx := fakecontext.New(c, "", fakecontext.WithFiles(files))
defer ctx.Close()
curdir, err := os.Getwd()

View file

@ -12,16 +12,13 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/testutil"
"gotest.tools/assert"
)
var ensureHTTPServerOnce sync.Once
func ensureHTTPServerImage(t testing.TB) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
var doIt bool
ensureHTTPServerOnce.Do(func() {
doIt = true

View file

@ -41,9 +41,7 @@ func SetTestEnvironment(env *environment.Execution) {
// 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 {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
if testEnv == nil {
t.Fatal("fakstorage package requires SetTestEnvironment() to be called before use.")
}

View file

@ -45,9 +45,7 @@ type Config struct {
// NewV2 creates a v2 registry server
func NewV2(t testing.TB, ops ...func(*Config)) *V2 {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
c := &Config{
registryURL: DefaultURL,
}
@ -130,9 +128,7 @@ http:
// WaitReady waits for the registry to be ready to serve requests (or fail after a while)
func (r *V2) WaitReady(t testing.TB) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
var err error
for i := 0; i != 50; i++ {
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
// malicious blob of data for example.
func (r *V2) TempMoveBlobData(t testing.TB, blobDigest digest.Digest) (undo func()) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
tempFile, err := ioutil.TempFile("", "registry-temp-blob-")
assert.NilError(t, err, "unable to get temporary blob file")
tempFile.Close()

View file

@ -7,8 +7,6 @@ import (
"strings"
"sync"
"testing"
"github.com/docker/docker/testutil"
)
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
func NewMock(t testing.TB) (*Mock, error) {
if ht, ok := t.(testutil.HelperT); ok {
ht.Helper()
}
t.Helper()
testReg := &Mock{handlers: make(map[string]handlerFunc)}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {