Browse Source

Remove some uses of testutil.HelperT

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 5 năm trước cách đây
mục cha
commit
0d4ffa3588

+ 7 - 21
testutil/daemon/daemon.go

@@ -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 {

+ 1 - 4
testutil/daemon/daemon_unix.go

@@ -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

+ 4 - 12
testutil/daemon/swarm.go

@@ -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)

+ 2 - 7
testutil/fakecontext/context.go

@@ -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)

+ 1 - 4
testutil/fakegit/fakegit.go

@@ -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()

+ 1 - 4
testutil/fakestorage/fixtures.go

@@ -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

+ 1 - 3
testutil/fakestorage/storage.go

@@ -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.")
 	}

+ 3 - 9
testutil/registry/registry.go

@@ -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()

+ 1 - 5
testutil/registry/registry_mock.go

@@ -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) {