That way, those lines won't be reported in the failure.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
| ... | ... |
@@ -13,6 +13,7 @@ import ( |
| 13 | 13 |
// HasHubConnectivity checks to see if https://hub.docker.com is |
| 14 | 14 |
// accessible from the present environment |
| 15 | 15 |
func HasHubConnectivity(t *testing.T) bool {
|
| 16 |
+ t.Helper() |
|
| 16 | 17 |
// Set a timeout on the GET at 15s |
| 17 | 18 |
var timeout = 15 * time.Second |
| 18 | 19 |
var url = "https://hub.docker.com" |
| ... | ... |
@@ -49,6 +49,7 @@ func ContainerPoll(config *poll.Settings) {
|
| 49 | 49 |
|
| 50 | 50 |
// NewSwarm creates a swarm daemon for testing |
| 51 | 51 |
func NewSwarm(t *testing.T, testEnv *environment.Execution, ops ...func(*daemon.Daemon)) *daemon.Daemon {
|
| 52 |
+ t.Helper() |
|
| 52 | 53 |
skip.IfCondition(t, testEnv.IsRemoteDaemon()) |
| 53 | 54 |
if testEnv.DaemonInfo.ExperimentalBuild {
|
| 54 | 55 |
ops = append(ops, daemon.WithExperimental) |
| ... | ... |
@@ -63,6 +64,7 @@ type ServiceSpecOpt func(*swarmtypes.ServiceSpec) |
| 63 | 63 |
|
| 64 | 64 |
// CreateService creates a service on the passed in swarm daemon. |
| 65 | 65 |
func CreateService(t *testing.T, d *daemon.Daemon, opts ...ServiceSpecOpt) string {
|
| 66 |
+ t.Helper() |
|
| 66 | 67 |
spec := defaultServiceSpec() |
| 67 | 68 |
for _, o := range opts {
|
| 68 | 69 |
o(&spec) |
| ... | ... |
@@ -136,6 +138,7 @@ func ServiceWithName(name string) ServiceSpecOpt {
|
| 136 | 136 |
|
| 137 | 137 |
// GetRunningTasks gets the list of running tasks for a service |
| 138 | 138 |
func GetRunningTasks(t *testing.T, d *daemon.Daemon, serviceID string) []swarmtypes.Task {
|
| 139 |
+ t.Helper() |
|
| 139 | 140 |
client := d.NewClientT(t) |
| 140 | 141 |
defer client.Close() |
| 141 | 142 |
|
| ... | ... |
@@ -153,6 +156,7 @@ func GetRunningTasks(t *testing.T, d *daemon.Daemon, serviceID string) []swarmty |
| 153 | 153 |
|
| 154 | 154 |
// ExecTask runs the passed in exec config on the given task |
| 155 | 155 |
func ExecTask(t *testing.T, d *daemon.Daemon, task swarmtypes.Task, config types.ExecConfig) types.HijackedResponse {
|
| 156 |
+ t.Helper() |
|
| 156 | 157 |
client := d.NewClientT(t) |
| 157 | 158 |
defer client.Close() |
| 158 | 159 |
|
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
|
| 6 | 6 |
"github.com/docker/docker/api/types" |
| 7 | 7 |
"github.com/docker/docker/api/types/swarm" |
| 8 |
+ "github.com/docker/docker/internal/test" |
|
| 8 | 9 |
"github.com/gotestyourself/gotestyourself/assert" |
| 9 | 10 |
) |
| 10 | 11 |
|
| ... | ... |
@@ -13,6 +14,9 @@ type ConfigConstructor func(*swarm.Config) |
| 13 | 13 |
|
| 14 | 14 |
// CreateConfig creates a config given the specified spec |
| 15 | 15 |
func (d *Daemon) CreateConfig(t assert.TestingT, configSpec swarm.ConfigSpec) string {
|
| 16 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 17 |
+ ht.Helper() |
|
| 18 |
+ } |
|
| 16 | 19 |
cli := d.NewClientT(t) |
| 17 | 20 |
defer cli.Close() |
| 18 | 21 |
|
| ... | ... |
@@ -23,6 +27,9 @@ func (d *Daemon) CreateConfig(t assert.TestingT, configSpec swarm.ConfigSpec) st |
| 23 | 23 |
|
| 24 | 24 |
// ListConfigs returns the list of the current swarm configs |
| 25 | 25 |
func (d *Daemon) ListConfigs(t assert.TestingT) []swarm.Config {
|
| 26 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 27 |
+ ht.Helper() |
|
| 28 |
+ } |
|
| 26 | 29 |
cli := d.NewClientT(t) |
| 27 | 30 |
defer cli.Close() |
| 28 | 31 |
|
| ... | ... |
@@ -33,6 +40,9 @@ func (d *Daemon) ListConfigs(t assert.TestingT) []swarm.Config {
|
| 33 | 33 |
|
| 34 | 34 |
// GetConfig returns a swarm config identified by the specified id |
| 35 | 35 |
func (d *Daemon) GetConfig(t assert.TestingT, id string) *swarm.Config {
|
| 36 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 37 |
+ ht.Helper() |
|
| 38 |
+ } |
|
| 36 | 39 |
cli := d.NewClientT(t) |
| 37 | 40 |
defer cli.Close() |
| 38 | 41 |
|
| ... | ... |
@@ -43,6 +53,9 @@ func (d *Daemon) GetConfig(t assert.TestingT, id string) *swarm.Config {
|
| 43 | 43 |
|
| 44 | 44 |
// DeleteConfig removes the swarm config identified by the specified id |
| 45 | 45 |
func (d *Daemon) DeleteConfig(t assert.TestingT, id string) {
|
| 46 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 47 |
+ ht.Helper() |
|
| 48 |
+ } |
|
| 46 | 49 |
cli := d.NewClientT(t) |
| 47 | 50 |
defer cli.Close() |
| 48 | 51 |
|
| ... | ... |
@@ -53,6 +66,9 @@ func (d *Daemon) DeleteConfig(t assert.TestingT, id string) {
|
| 53 | 53 |
// UpdateConfig updates the swarm config identified by the specified id |
| 54 | 54 |
// Currently, only label update is supported. |
| 55 | 55 |
func (d *Daemon) UpdateConfig(t assert.TestingT, id string, f ...ConfigConstructor) {
|
| 56 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 57 |
+ ht.Helper() |
|
| 58 |
+ } |
|
| 56 | 59 |
cli := d.NewClientT(t) |
| 57 | 60 |
defer cli.Close() |
| 58 | 61 |
|
| ... | ... |
@@ -4,11 +4,15 @@ import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
|
| 6 | 6 |
"github.com/docker/docker/api/types" |
| 7 |
+ "github.com/docker/docker/internal/test" |
|
| 7 | 8 |
"github.com/gotestyourself/gotestyourself/assert" |
| 8 | 9 |
) |
| 9 | 10 |
|
| 10 | 11 |
// ActiveContainers returns the list of ids of the currently running containers |
| 11 | 12 |
func (d *Daemon) ActiveContainers(t assert.TestingT) []string {
|
| 13 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 14 |
+ ht.Helper() |
|
| 15 |
+ } |
|
| 12 | 16 |
cli := d.NewClientT(t) |
| 13 | 17 |
defer cli.Close() |
| 14 | 18 |
|
| ... | ... |
@@ -24,6 +28,9 @@ func (d *Daemon) ActiveContainers(t assert.TestingT) []string {
|
| 24 | 24 |
|
| 25 | 25 |
// FindContainerIP returns the ip of the specified container |
| 26 | 26 |
func (d *Daemon) FindContainerIP(t assert.TestingT, id string) string {
|
| 27 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 28 |
+ ht.Helper() |
|
| 29 |
+ } |
|
| 27 | 30 |
cli := d.NewClientT(t) |
| 28 | 31 |
defer cli.Close() |
| 29 | 32 |
|
| ... | ... |
@@ -16,6 +16,7 @@ import ( |
| 16 | 16 |
"github.com/docker/docker/api/types" |
| 17 | 17 |
"github.com/docker/docker/api/types/events" |
| 18 | 18 |
"github.com/docker/docker/client" |
| 19 |
+ "github.com/docker/docker/internal/test" |
|
| 19 | 20 |
"github.com/docker/docker/internal/test/request" |
| 20 | 21 |
"github.com/docker/docker/opts" |
| 21 | 22 |
"github.com/docker/docker/pkg/ioutils" |
| ... | ... |
@@ -80,6 +81,9 @@ type Daemon struct {
|
| 80 | 80 |
// This will create a directory such as d123456789 in the folder specified by $DOCKER_INTEGRATION_DAEMON_DEST or $DEST. |
| 81 | 81 |
// The daemon will not automatically start. |
| 82 | 82 |
func New(t testingT, ops ...func(*Daemon)) *Daemon {
|
| 83 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 84 |
+ ht.Helper() |
|
| 85 |
+ } |
|
| 83 | 86 |
dest := os.Getenv("DOCKER_INTEGRATION_DAEMON_DEST")
|
| 84 | 87 |
if dest == "" {
|
| 85 | 88 |
dest = os.Getenv("DEST")
|
| ... | ... |
@@ -169,6 +173,9 @@ func (d *Daemon) NewClient() (*client.Client, error) {
|
| 169 | 169 |
// NewClientT creates new client based on daemon's socket path |
| 170 | 170 |
// FIXME(vdemeester): replace NewClient with NewClientT |
| 171 | 171 |
func (d *Daemon) NewClientT(t assert.TestingT) *client.Client {
|
| 172 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 173 |
+ ht.Helper() |
|
| 174 |
+ } |
|
| 172 | 175 |
c, err := client.NewClientWithOpts( |
| 173 | 176 |
client.FromEnv, |
| 174 | 177 |
client.WithHost(d.Sock())) |
| ... | ... |
@@ -178,6 +185,9 @@ func (d *Daemon) NewClientT(t assert.TestingT) *client.Client {
|
| 178 | 178 |
|
| 179 | 179 |
// Cleanup cleans the daemon files : exec root (network namespaces, ...), swarmkit files |
| 180 | 180 |
func (d *Daemon) Cleanup(t testingT) {
|
| 181 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 182 |
+ ht.Helper() |
|
| 183 |
+ } |
|
| 181 | 184 |
// Cleanup swarmkit wal files if present |
| 182 | 185 |
cleanupRaftDir(t, d.Root) |
| 183 | 186 |
cleanupNetworkNamespace(t, d.execRoot) |
| ... | ... |
@@ -185,6 +195,9 @@ func (d *Daemon) Cleanup(t testingT) {
|
| 185 | 185 |
|
| 186 | 186 |
// Start starts the daemon and return once it is ready to receive requests. |
| 187 | 187 |
func (d *Daemon) Start(t testingT, args ...string) {
|
| 188 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 189 |
+ ht.Helper() |
|
| 190 |
+ } |
|
| 188 | 191 |
if err := d.StartWithError(args...); err != nil {
|
| 189 | 192 |
t.Fatalf("Error starting daemon with arguments: %v", args)
|
| 190 | 193 |
} |
| ... | ... |
@@ -316,6 +329,9 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
|
| 316 | 316 |
// StartWithBusybox will first start the daemon with Daemon.Start() |
| 317 | 317 |
// then save the busybox image from the main daemon and load it into this Daemon instance. |
| 318 | 318 |
func (d *Daemon) StartWithBusybox(t testingT, arg ...string) {
|
| 319 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 320 |
+ ht.Helper() |
|
| 321 |
+ } |
|
| 319 | 322 |
d.Start(t, arg...) |
| 320 | 323 |
d.LoadBusybox(t) |
| 321 | 324 |
} |
| ... | ... |
@@ -372,6 +388,9 @@ func (d *Daemon) DumpStackAndQuit() {
|
| 372 | 372 |
// instantiate a new one with NewDaemon. |
| 373 | 373 |
// If an error occurs while starting the daemon, the test will fail. |
| 374 | 374 |
func (d *Daemon) Stop(t testingT) {
|
| 375 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 376 |
+ ht.Helper() |
|
| 377 |
+ } |
|
| 375 | 378 |
err := d.StopWithError() |
| 376 | 379 |
if err != nil {
|
| 377 | 380 |
if err != errDaemonNotStarted {
|
| ... | ... |
@@ -448,6 +467,9 @@ out2: |
| 448 | 448 |
// Restart will restart the daemon by first stopping it and the starting it. |
| 449 | 449 |
// If an error occurs while starting the daemon, the test will fail. |
| 450 | 450 |
func (d *Daemon) Restart(t testingT, args ...string) {
|
| 451 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 452 |
+ ht.Helper() |
|
| 453 |
+ } |
|
| 451 | 454 |
d.Stop(t) |
| 452 | 455 |
d.Start(t, args...) |
| 453 | 456 |
} |
| ... | ... |
@@ -521,6 +543,9 @@ func (d *Daemon) ReloadConfig() error {
|
| 521 | 521 |
|
| 522 | 522 |
// LoadBusybox image into the daemon |
| 523 | 523 |
func (d *Daemon) LoadBusybox(t assert.TestingT) {
|
| 524 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 525 |
+ ht.Helper() |
|
| 526 |
+ } |
|
| 524 | 527 |
clientHost, err := client.NewEnvClient() |
| 525 | 528 |
assert.NilError(t, err, "failed to create client") |
| 526 | 529 |
defer clientHost.Close() |
| ... | ... |
@@ -631,6 +656,9 @@ func (d *Daemon) queryRootDir() (string, error) {
|
| 631 | 631 |
|
| 632 | 632 |
// Info returns the info struct for this daemon |
| 633 | 633 |
func (d *Daemon) Info(t assert.TestingT) types.Info {
|
| 634 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 635 |
+ ht.Helper() |
|
| 636 |
+ } |
|
| 634 | 637 |
apiclient, err := d.NewClient() |
| 635 | 638 |
assert.NilError(t, err) |
| 636 | 639 |
info, err := apiclient.Info(context.Background()) |
| ... | ... |
@@ -639,6 +667,9 @@ func (d *Daemon) Info(t assert.TestingT) types.Info {
|
| 639 | 639 |
} |
| 640 | 640 |
|
| 641 | 641 |
func cleanupRaftDir(t testingT, rootPath string) {
|
| 642 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 643 |
+ ht.Helper() |
|
| 644 |
+ } |
|
| 642 | 645 |
walDir := filepath.Join(rootPath, "swarm/raft/wal") |
| 643 | 646 |
if err := os.RemoveAll(walDir); err != nil {
|
| 644 | 647 |
t.Logf("error removing %v: %v", walDir, err)
|
| ... | ... |
@@ -6,10 +6,14 @@ import ( |
| 6 | 6 |
"os" |
| 7 | 7 |
"path/filepath" |
| 8 | 8 |
|
| 9 |
+ "github.com/docker/docker/internal/test" |
|
| 9 | 10 |
"golang.org/x/sys/unix" |
| 10 | 11 |
) |
| 11 | 12 |
|
| 12 | 13 |
func cleanupNetworkNamespace(t testingT, execRoot string) {
|
| 14 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 15 |
+ ht.Helper() |
|
| 16 |
+ } |
|
| 13 | 17 |
// Cleanup network namespaces in the exec root of this |
| 14 | 18 |
// daemon because this exec root is specific to this |
| 15 | 19 |
// daemon instance and has no chance of getting |
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
|
| 8 | 8 |
"github.com/docker/docker/api/types" |
| 9 | 9 |
"github.com/docker/docker/api/types/swarm" |
| 10 |
+ "github.com/docker/docker/internal/test" |
|
| 10 | 11 |
"github.com/gotestyourself/gotestyourself/assert" |
| 11 | 12 |
) |
| 12 | 13 |
|
| ... | ... |
@@ -15,6 +16,9 @@ type NodeConstructor func(*swarm.Node) |
| 15 | 15 |
|
| 16 | 16 |
// GetNode returns a swarm node identified by the specified id |
| 17 | 17 |
func (d *Daemon) GetNode(t assert.TestingT, id string) *swarm.Node {
|
| 18 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 19 |
+ ht.Helper() |
|
| 20 |
+ } |
|
| 18 | 21 |
cli := d.NewClientT(t) |
| 19 | 22 |
defer cli.Close() |
| 20 | 23 |
|
| ... | ... |
@@ -26,6 +30,9 @@ func (d *Daemon) GetNode(t assert.TestingT, id string) *swarm.Node {
|
| 26 | 26 |
|
| 27 | 27 |
// RemoveNode removes the specified node |
| 28 | 28 |
func (d *Daemon) RemoveNode(t assert.TestingT, id string, force bool) {
|
| 29 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 30 |
+ ht.Helper() |
|
| 31 |
+ } |
|
| 29 | 32 |
cli := d.NewClientT(t) |
| 30 | 33 |
defer cli.Close() |
| 31 | 34 |
|
| ... | ... |
@@ -38,6 +45,9 @@ func (d *Daemon) RemoveNode(t assert.TestingT, id string, force bool) {
|
| 38 | 38 |
|
| 39 | 39 |
// UpdateNode updates a swarm node with the specified node constructor |
| 40 | 40 |
func (d *Daemon) UpdateNode(t assert.TestingT, id string, f ...NodeConstructor) {
|
| 41 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 42 |
+ ht.Helper() |
|
| 43 |
+ } |
|
| 41 | 44 |
cli := d.NewClientT(t) |
| 42 | 45 |
defer cli.Close() |
| 43 | 46 |
|
| ... | ... |
@@ -59,6 +69,9 @@ func (d *Daemon) UpdateNode(t assert.TestingT, id string, f ...NodeConstructor) |
| 59 | 59 |
|
| 60 | 60 |
// ListNodes returns the list of the current swarm nodes |
| 61 | 61 |
func (d *Daemon) ListNodes(t assert.TestingT) []swarm.Node {
|
| 62 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 63 |
+ ht.Helper() |
|
| 64 |
+ } |
|
| 62 | 65 |
cli := d.NewClientT(t) |
| 63 | 66 |
defer cli.Close() |
| 64 | 67 |
|
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
|
| 6 | 6 |
"github.com/docker/docker/api/types" |
| 7 | 7 |
"github.com/docker/docker/api/types/swarm" |
| 8 |
+ "github.com/docker/docker/internal/test" |
|
| 8 | 9 |
"github.com/gotestyourself/gotestyourself/assert" |
| 9 | 10 |
) |
| 10 | 11 |
|
| ... | ... |
@@ -13,6 +14,9 @@ type SecretConstructor func(*swarm.Secret) |
| 13 | 13 |
|
| 14 | 14 |
// CreateSecret creates a secret given the specified spec |
| 15 | 15 |
func (d *Daemon) CreateSecret(t assert.TestingT, secretSpec swarm.SecretSpec) string {
|
| 16 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 17 |
+ ht.Helper() |
|
| 18 |
+ } |
|
| 16 | 19 |
cli := d.NewClientT(t) |
| 17 | 20 |
defer cli.Close() |
| 18 | 21 |
|
| ... | ... |
@@ -24,6 +28,9 @@ func (d *Daemon) CreateSecret(t assert.TestingT, secretSpec swarm.SecretSpec) st |
| 24 | 24 |
|
| 25 | 25 |
// ListSecrets returns the list of the current swarm secrets |
| 26 | 26 |
func (d *Daemon) ListSecrets(t assert.TestingT) []swarm.Secret {
|
| 27 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 28 |
+ ht.Helper() |
|
| 29 |
+ } |
|
| 27 | 30 |
cli := d.NewClientT(t) |
| 28 | 31 |
defer cli.Close() |
| 29 | 32 |
|
| ... | ... |
@@ -34,6 +41,9 @@ func (d *Daemon) ListSecrets(t assert.TestingT) []swarm.Secret {
|
| 34 | 34 |
|
| 35 | 35 |
// GetSecret returns a swarm secret identified by the specified id |
| 36 | 36 |
func (d *Daemon) GetSecret(t assert.TestingT, id string) *swarm.Secret {
|
| 37 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 38 |
+ ht.Helper() |
|
| 39 |
+ } |
|
| 37 | 40 |
cli := d.NewClientT(t) |
| 38 | 41 |
defer cli.Close() |
| 39 | 42 |
|
| ... | ... |
@@ -44,6 +54,9 @@ func (d *Daemon) GetSecret(t assert.TestingT, id string) *swarm.Secret {
|
| 44 | 44 |
|
| 45 | 45 |
// DeleteSecret removes the swarm secret identified by the specified id |
| 46 | 46 |
func (d *Daemon) DeleteSecret(t assert.TestingT, id string) {
|
| 47 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 48 |
+ ht.Helper() |
|
| 49 |
+ } |
|
| 47 | 50 |
cli := d.NewClientT(t) |
| 48 | 51 |
defer cli.Close() |
| 49 | 52 |
|
| ... | ... |
@@ -54,6 +67,9 @@ func (d *Daemon) DeleteSecret(t assert.TestingT, id string) {
|
| 54 | 54 |
// UpdateSecret updates the swarm secret identified by the specified id |
| 55 | 55 |
// Currently, only label update is supported. |
| 56 | 56 |
func (d *Daemon) UpdateSecret(t assert.TestingT, id string, f ...SecretConstructor) {
|
| 57 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 58 |
+ ht.Helper() |
|
| 59 |
+ } |
|
| 57 | 60 |
cli := d.NewClientT(t) |
| 58 | 61 |
defer cli.Close() |
| 59 | 62 |
|
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"github.com/docker/docker/api/types" |
| 8 | 8 |
"github.com/docker/docker/api/types/filters" |
| 9 | 9 |
"github.com/docker/docker/api/types/swarm" |
| 10 |
+ "github.com/docker/docker/internal/test" |
|
| 10 | 11 |
"github.com/gotestyourself/gotestyourself/assert" |
| 11 | 12 |
) |
| 12 | 13 |
|
| ... | ... |
@@ -14,6 +15,9 @@ import ( |
| 14 | 14 |
type ServiceConstructor func(*swarm.Service) |
| 15 | 15 |
|
| 16 | 16 |
func (d *Daemon) createServiceWithOptions(t assert.TestingT, opts types.ServiceCreateOptions, f ...ServiceConstructor) string {
|
| 17 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 18 |
+ ht.Helper() |
|
| 19 |
+ } |
|
| 17 | 20 |
var service swarm.Service |
| 18 | 21 |
for _, fn := range f {
|
| 19 | 22 |
fn(&service) |
| ... | ... |
@@ -32,11 +36,17 @@ func (d *Daemon) createServiceWithOptions(t assert.TestingT, opts types.ServiceC |
| 32 | 32 |
|
| 33 | 33 |
// CreateService creates a swarm service given the specified service constructor |
| 34 | 34 |
func (d *Daemon) CreateService(t assert.TestingT, f ...ServiceConstructor) string {
|
| 35 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 36 |
+ ht.Helper() |
|
| 37 |
+ } |
|
| 35 | 38 |
return d.createServiceWithOptions(t, types.ServiceCreateOptions{}, f...)
|
| 36 | 39 |
} |
| 37 | 40 |
|
| 38 | 41 |
// GetService returns the swarm service corresponding to the specified id |
| 39 | 42 |
func (d *Daemon) GetService(t assert.TestingT, id string) *swarm.Service {
|
| 43 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 44 |
+ ht.Helper() |
|
| 45 |
+ } |
|
| 40 | 46 |
cli := d.NewClientT(t) |
| 41 | 47 |
defer cli.Close() |
| 42 | 48 |
|
| ... | ... |
@@ -47,6 +57,9 @@ func (d *Daemon) GetService(t assert.TestingT, id string) *swarm.Service {
|
| 47 | 47 |
|
| 48 | 48 |
// GetServiceTasks returns the swarm tasks for the specified service |
| 49 | 49 |
func (d *Daemon) GetServiceTasks(t assert.TestingT, service string) []swarm.Task {
|
| 50 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 51 |
+ ht.Helper() |
|
| 52 |
+ } |
|
| 50 | 53 |
cli := d.NewClientT(t) |
| 51 | 54 |
defer cli.Close() |
| 52 | 55 |
|
| ... | ... |
@@ -65,6 +78,9 @@ func (d *Daemon) GetServiceTasks(t assert.TestingT, service string) []swarm.Task |
| 65 | 65 |
|
| 66 | 66 |
// UpdateService updates a swarm service with the specified service constructor |
| 67 | 67 |
func (d *Daemon) UpdateService(t assert.TestingT, service *swarm.Service, f ...ServiceConstructor) {
|
| 68 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 69 |
+ ht.Helper() |
|
| 70 |
+ } |
|
| 68 | 71 |
cli := d.NewClientT(t) |
| 69 | 72 |
defer cli.Close() |
| 70 | 73 |
|
| ... | ... |
@@ -78,6 +94,9 @@ func (d *Daemon) UpdateService(t assert.TestingT, service *swarm.Service, f ...S |
| 78 | 78 |
|
| 79 | 79 |
// RemoveService removes the specified service |
| 80 | 80 |
func (d *Daemon) RemoveService(t assert.TestingT, id string) {
|
| 81 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 82 |
+ ht.Helper() |
|
| 83 |
+ } |
|
| 81 | 84 |
cli := d.NewClientT(t) |
| 82 | 85 |
defer cli.Close() |
| 83 | 86 |
|
| ... | ... |
@@ -87,6 +106,9 @@ func (d *Daemon) RemoveService(t assert.TestingT, id string) {
|
| 87 | 87 |
|
| 88 | 88 |
// ListServices returns the list of the current swarm services |
| 89 | 89 |
func (d *Daemon) ListServices(t assert.TestingT) []swarm.Service {
|
| 90 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 91 |
+ ht.Helper() |
|
| 92 |
+ } |
|
| 90 | 93 |
cli := d.NewClientT(t) |
| 91 | 94 |
defer cli.Close() |
| 92 | 95 |
|
| ... | ... |
@@ -97,6 +119,9 @@ func (d *Daemon) ListServices(t assert.TestingT) []swarm.Service {
|
| 97 | 97 |
|
| 98 | 98 |
// GetTask returns the swarm task identified by the specified id |
| 99 | 99 |
func (d *Daemon) GetTask(t assert.TestingT, id string) swarm.Task {
|
| 100 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 101 |
+ ht.Helper() |
|
| 102 |
+ } |
|
| 100 | 103 |
cli := d.NewClientT(t) |
| 101 | 104 |
defer cli.Close() |
| 102 | 105 |
|
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"fmt" |
| 6 | 6 |
|
| 7 | 7 |
"github.com/docker/docker/api/types/swarm" |
| 8 |
+ "github.com/docker/docker/internal/test" |
|
| 8 | 9 |
"github.com/gotestyourself/gotestyourself/assert" |
| 9 | 10 |
"github.com/pkg/errors" |
| 10 | 11 |
) |
| ... | ... |
@@ -17,6 +18,9 @@ const ( |
| 17 | 17 |
|
| 18 | 18 |
// StartAndSwarmInit starts the daemon (with busybox) and init the swarm |
| 19 | 19 |
func (d *Daemon) StartAndSwarmInit(t testingT) {
|
| 20 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 21 |
+ ht.Helper() |
|
| 22 |
+ } |
|
| 20 | 23 |
// avoid networking conflicts |
| 21 | 24 |
args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
|
| 22 | 25 |
d.StartWithBusybox(t, args...) |
| ... | ... |
@@ -26,6 +30,9 @@ func (d *Daemon) StartAndSwarmInit(t testingT) {
|
| 26 | 26 |
|
| 27 | 27 |
// StartAndSwarmJoin starts the daemon (with busybox) and join the specified swarm as worker or manager |
| 28 | 28 |
func (d *Daemon) StartAndSwarmJoin(t testingT, leader *Daemon, manager bool) {
|
| 29 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 30 |
+ ht.Helper() |
|
| 31 |
+ } |
|
| 29 | 32 |
// avoid networking conflicts |
| 30 | 33 |
args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
|
| 31 | 34 |
d.StartWithBusybox(t, args...) |
| ... | ... |
@@ -56,6 +63,9 @@ func (d *Daemon) NodeID() string {
|
| 56 | 56 |
|
| 57 | 57 |
// SwarmInit initializes a new swarm cluster. |
| 58 | 58 |
func (d *Daemon) SwarmInit(t assert.TestingT, req swarm.InitRequest) {
|
| 59 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 60 |
+ ht.Helper() |
|
| 61 |
+ } |
|
| 59 | 62 |
if req.ListenAddr == "" {
|
| 60 | 63 |
req.ListenAddr = fmt.Sprintf("%s:%d", d.swarmListenAddr, d.SwarmPort)
|
| 61 | 64 |
} |
| ... | ... |
@@ -68,6 +78,9 @@ func (d *Daemon) SwarmInit(t assert.TestingT, req swarm.InitRequest) {
|
| 68 | 68 |
|
| 69 | 69 |
// SwarmJoin joins a daemon to an existing cluster. |
| 70 | 70 |
func (d *Daemon) SwarmJoin(t assert.TestingT, req swarm.JoinRequest) {
|
| 71 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 72 |
+ ht.Helper() |
|
| 73 |
+ } |
|
| 71 | 74 |
if req.ListenAddr == "" {
|
| 72 | 75 |
req.ListenAddr = fmt.Sprintf("%s:%d", d.swarmListenAddr, d.SwarmPort)
|
| 73 | 76 |
} |
| ... | ... |
@@ -94,6 +107,9 @@ func (d *Daemon) SwarmLeave(force bool) error {
|
| 94 | 94 |
|
| 95 | 95 |
// SwarmInfo returns the swarm information of the daemon |
| 96 | 96 |
func (d *Daemon) SwarmInfo(t assert.TestingT) swarm.Info {
|
| 97 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 98 |
+ ht.Helper() |
|
| 99 |
+ } |
|
| 97 | 100 |
cli := d.NewClientT(t) |
| 98 | 101 |
info, err := cli.Info(context.Background()) |
| 99 | 102 |
assert.NilError(t, err, "get swarm info") |
| ... | ... |
@@ -116,6 +132,9 @@ func (d *Daemon) SwarmUnlock(req swarm.UnlockRequest) error {
|
| 116 | 116 |
|
| 117 | 117 |
// GetSwarm returns the current swarm object |
| 118 | 118 |
func (d *Daemon) GetSwarm(t assert.TestingT) swarm.Swarm {
|
| 119 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 120 |
+ ht.Helper() |
|
| 121 |
+ } |
|
| 119 | 122 |
cli := d.NewClientT(t) |
| 120 | 123 |
defer cli.Close() |
| 121 | 124 |
|
| ... | ... |
@@ -126,6 +145,9 @@ func (d *Daemon) GetSwarm(t assert.TestingT) swarm.Swarm {
|
| 126 | 126 |
|
| 127 | 127 |
// UpdateSwarm updates the current swarm object with the specified spec constructors |
| 128 | 128 |
func (d *Daemon) UpdateSwarm(t assert.TestingT, f ...SpecConstructor) {
|
| 129 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 130 |
+ ht.Helper() |
|
| 131 |
+ } |
|
| 129 | 132 |
cli := d.NewClientT(t) |
| 130 | 133 |
defer cli.Close() |
| 131 | 134 |
|
| ... | ... |
@@ -140,6 +162,9 @@ func (d *Daemon) UpdateSwarm(t assert.TestingT, f ...SpecConstructor) {
|
| 140 | 140 |
|
| 141 | 141 |
// RotateTokens update the swarm to rotate tokens |
| 142 | 142 |
func (d *Daemon) RotateTokens(t assert.TestingT) {
|
| 143 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 144 |
+ ht.Helper() |
|
| 145 |
+ } |
|
| 143 | 146 |
cli := d.NewClientT(t) |
| 144 | 147 |
defer cli.Close() |
| 145 | 148 |
|
| ... | ... |
@@ -157,6 +182,9 @@ func (d *Daemon) RotateTokens(t assert.TestingT) {
|
| 157 | 157 |
|
| 158 | 158 |
// JoinTokens returns the current swarm join tokens |
| 159 | 159 |
func (d *Daemon) JoinTokens(t assert.TestingT) swarm.JoinTokens {
|
| 160 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 161 |
+ ht.Helper() |
|
| 162 |
+ } |
|
| 160 | 163 |
cli := d.NewClientT(t) |
| 161 | 164 |
defer cli.Close() |
| 162 | 165 |
|
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"github.com/docker/docker/api/types" |
| 8 | 8 |
"github.com/docker/docker/api/types/filters" |
| 9 | 9 |
"github.com/docker/docker/client" |
| 10 |
+ "github.com/docker/docker/internal/test" |
|
| 10 | 11 |
"github.com/gotestyourself/gotestyourself/assert" |
| 11 | 12 |
"golang.org/x/net/context" |
| 12 | 13 |
) |
| ... | ... |
@@ -25,6 +26,9 @@ type logT interface {
|
| 25 | 25 |
// and removing everything else. It's meant to run after any tests so that they don't |
| 26 | 26 |
// depend on each others. |
| 27 | 27 |
func (e *Execution) Clean(t testingT) {
|
| 28 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 29 |
+ ht.Helper() |
|
| 30 |
+ } |
|
| 28 | 31 |
client := e.APIClient() |
| 29 | 32 |
|
| 30 | 33 |
platform := e.OSType |
| ... | ... |
@@ -41,6 +45,9 @@ func (e *Execution) Clean(t testingT) {
|
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 | 43 |
func unpauseAllContainers(t assert.TestingT, client client.ContainerAPIClient) {
|
| 44 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 45 |
+ ht.Helper() |
|
| 46 |
+ } |
|
| 44 | 47 |
ctx := context.Background() |
| 45 | 48 |
containers := getPausedContainers(ctx, t, client) |
| 46 | 49 |
if len(containers) > 0 {
|
| ... | ... |
@@ -52,6 +59,9 @@ func unpauseAllContainers(t assert.TestingT, client client.ContainerAPIClient) {
|
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 | 54 |
func getPausedContainers(ctx context.Context, t assert.TestingT, client client.ContainerAPIClient) []types.Container {
|
| 55 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 56 |
+ ht.Helper() |
|
| 57 |
+ } |
|
| 55 | 58 |
filter := filters.NewArgs() |
| 56 | 59 |
filter.Add("status", "paused")
|
| 57 | 60 |
containers, err := client.ContainerList(ctx, types.ContainerListOptions{
|
| ... | ... |
@@ -66,6 +76,9 @@ func getPausedContainers(ctx context.Context, t assert.TestingT, client client.C |
| 66 | 66 |
var alreadyExists = regexp.MustCompile(`Error response from daemon: removal of container (\w+) is already in progress`) |
| 67 | 67 |
|
| 68 | 68 |
func deleteAllContainers(t assert.TestingT, apiclient client.ContainerAPIClient, protectedContainers map[string]struct{}) {
|
| 69 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 70 |
+ ht.Helper() |
|
| 71 |
+ } |
|
| 69 | 72 |
ctx := context.Background() |
| 70 | 73 |
containers := getAllContainers(ctx, t, apiclient) |
| 71 | 74 |
if len(containers) == 0 {
|
| ... | ... |
@@ -88,6 +101,9 @@ func deleteAllContainers(t assert.TestingT, apiclient client.ContainerAPIClient, |
| 88 | 88 |
} |
| 89 | 89 |
|
| 90 | 90 |
func getAllContainers(ctx context.Context, t assert.TestingT, client client.ContainerAPIClient) []types.Container {
|
| 91 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 92 |
+ ht.Helper() |
|
| 93 |
+ } |
|
| 91 | 94 |
containers, err := client.ContainerList(ctx, types.ContainerListOptions{
|
| 92 | 95 |
Quiet: true, |
| 93 | 96 |
All: true, |
| ... | ... |
@@ -97,6 +113,9 @@ func getAllContainers(ctx context.Context, t assert.TestingT, client client.Cont |
| 97 | 97 |
} |
| 98 | 98 |
|
| 99 | 99 |
func deleteAllImages(t testingT, apiclient client.ImageAPIClient, protectedImages map[string]struct{}) {
|
| 100 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 101 |
+ ht.Helper() |
|
| 102 |
+ } |
|
| 100 | 103 |
images, err := apiclient.ImageList(context.Background(), types.ImageListOptions{})
|
| 101 | 104 |
assert.Check(t, err, "failed to list images") |
| 102 | 105 |
|
| ... | ... |
@@ -119,6 +138,9 @@ func deleteAllImages(t testingT, apiclient client.ImageAPIClient, protectedImage |
| 119 | 119 |
} |
| 120 | 120 |
|
| 121 | 121 |
func removeImage(ctx context.Context, t assert.TestingT, apiclient client.ImageAPIClient, ref string) {
|
| 122 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 123 |
+ ht.Helper() |
|
| 124 |
+ } |
|
| 122 | 125 |
_, err := apiclient.ImageRemove(ctx, ref, types.ImageRemoveOptions{
|
| 123 | 126 |
Force: true, |
| 124 | 127 |
}) |
| ... | ... |
@@ -129,6 +151,9 @@ func removeImage(ctx context.Context, t assert.TestingT, apiclient client.ImageA |
| 129 | 129 |
} |
| 130 | 130 |
|
| 131 | 131 |
func deleteAllVolumes(t assert.TestingT, c client.VolumeAPIClient, protectedVolumes map[string]struct{}) {
|
| 132 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 133 |
+ ht.Helper() |
|
| 134 |
+ } |
|
| 132 | 135 |
volumes, err := c.VolumeList(context.Background(), filters.Args{})
|
| 133 | 136 |
assert.Check(t, err, "failed to list volumes") |
| 134 | 137 |
|
| ... | ... |
@@ -146,6 +171,9 @@ func deleteAllVolumes(t assert.TestingT, c client.VolumeAPIClient, protectedVolu |
| 146 | 146 |
} |
| 147 | 147 |
|
| 148 | 148 |
func deleteAllNetworks(t assert.TestingT, c client.NetworkAPIClient, daemonPlatform string, protectedNetworks map[string]struct{}) {
|
| 149 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 150 |
+ ht.Helper() |
|
| 151 |
+ } |
|
| 149 | 152 |
networks, err := c.NetworkList(context.Background(), types.NetworkListOptions{})
|
| 150 | 153 |
assert.Check(t, err, "failed to list networks") |
| 151 | 154 |
|
| ... | ... |
@@ -166,6 +194,9 @@ func deleteAllNetworks(t assert.TestingT, c client.NetworkAPIClient, daemonPlatf |
| 166 | 166 |
} |
| 167 | 167 |
|
| 168 | 168 |
func deleteAllPlugins(t assert.TestingT, c client.PluginAPIClient, protectedPlugins map[string]struct{}) {
|
| 169 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 170 |
+ ht.Helper() |
|
| 171 |
+ } |
|
| 169 | 172 |
plugins, err := c.PluginList(context.Background(), filters.Args{})
|
| 170 | 173 |
// Docker EE does not allow cluster-wide plugin management. |
| 171 | 174 |
if client.IsErrNotImplemented(err) {
|
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"github.com/docker/docker/api/types" |
| 7 | 7 |
"github.com/docker/docker/api/types/filters" |
| 8 | 8 |
dclient "github.com/docker/docker/client" |
| 9 |
+ "github.com/docker/docker/internal/test" |
|
| 9 | 10 |
"github.com/gotestyourself/gotestyourself/assert" |
| 10 | 11 |
) |
| 11 | 12 |
|
| ... | ... |
@@ -33,6 +34,9 @@ func newProtectedElements() protectedElements {
|
| 33 | 33 |
// volumes, and, on Linux, plugins) from being cleaned up at the end of test |
| 34 | 34 |
// runs |
| 35 | 35 |
func ProtectAll(t testingT, testEnv *Execution) {
|
| 36 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 37 |
+ ht.Helper() |
|
| 38 |
+ } |
|
| 36 | 39 |
ProtectContainers(t, testEnv) |
| 37 | 40 |
ProtectImages(t, testEnv) |
| 38 | 41 |
ProtectNetworks(t, testEnv) |
| ... | ... |
@@ -45,6 +49,9 @@ func ProtectAll(t testingT, testEnv *Execution) {
|
| 45 | 45 |
// ProtectContainer adds the specified container(s) to be protected in case of |
| 46 | 46 |
// clean |
| 47 | 47 |
func (e *Execution) ProtectContainer(t testingT, containers ...string) {
|
| 48 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 49 |
+ ht.Helper() |
|
| 50 |
+ } |
|
| 48 | 51 |
for _, container := range containers {
|
| 49 | 52 |
e.protectedElements.containers[container] = struct{}{}
|
| 50 | 53 |
} |
| ... | ... |
@@ -53,11 +60,17 @@ func (e *Execution) ProtectContainer(t testingT, containers ...string) {
|
| 53 | 53 |
// ProtectContainers protects existing containers from being cleaned up at the |
| 54 | 54 |
// end of test runs |
| 55 | 55 |
func ProtectContainers(t testingT, testEnv *Execution) {
|
| 56 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 57 |
+ ht.Helper() |
|
| 58 |
+ } |
|
| 56 | 59 |
containers := getExistingContainers(t, testEnv) |
| 57 | 60 |
testEnv.ProtectContainer(t, containers...) |
| 58 | 61 |
} |
| 59 | 62 |
|
| 60 | 63 |
func getExistingContainers(t assert.TestingT, testEnv *Execution) []string {
|
| 64 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 65 |
+ ht.Helper() |
|
| 66 |
+ } |
|
| 61 | 67 |
client := testEnv.APIClient() |
| 62 | 68 |
containerList, err := client.ContainerList(context.Background(), types.ContainerListOptions{
|
| 63 | 69 |
All: true, |
| ... | ... |
@@ -73,6 +86,9 @@ func getExistingContainers(t assert.TestingT, testEnv *Execution) []string {
|
| 73 | 73 |
|
| 74 | 74 |
// ProtectImage adds the specified image(s) to be protected in case of clean |
| 75 | 75 |
func (e *Execution) ProtectImage(t testingT, images ...string) {
|
| 76 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 77 |
+ ht.Helper() |
|
| 78 |
+ } |
|
| 76 | 79 |
for _, image := range images {
|
| 77 | 80 |
e.protectedElements.images[image] = struct{}{}
|
| 78 | 81 |
} |
| ... | ... |
@@ -81,6 +97,9 @@ func (e *Execution) ProtectImage(t testingT, images ...string) {
|
| 81 | 81 |
// ProtectImages protects existing images and on linux frozen images from being |
| 82 | 82 |
// cleaned up at the end of test runs |
| 83 | 83 |
func ProtectImages(t testingT, testEnv *Execution) {
|
| 84 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 85 |
+ ht.Helper() |
|
| 86 |
+ } |
|
| 84 | 87 |
images := getExistingImages(t, testEnv) |
| 85 | 88 |
|
| 86 | 89 |
if testEnv.OSType == "linux" {
|
| ... | ... |
@@ -90,6 +109,9 @@ func ProtectImages(t testingT, testEnv *Execution) {
|
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 | 92 |
func getExistingImages(t assert.TestingT, testEnv *Execution) []string {
|
| 93 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 94 |
+ ht.Helper() |
|
| 95 |
+ } |
|
| 93 | 96 |
client := testEnv.APIClient() |
| 94 | 97 |
filter := filters.NewArgs() |
| 95 | 98 |
filter.Add("dangling", "false")
|
| ... | ... |
@@ -124,6 +146,9 @@ func tagsFromImageSummary(image types.ImageSummary) []string {
|
| 124 | 124 |
// ProtectNetwork adds the specified network(s) to be protected in case of |
| 125 | 125 |
// clean |
| 126 | 126 |
func (e *Execution) ProtectNetwork(t testingT, networks ...string) {
|
| 127 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 128 |
+ ht.Helper() |
|
| 129 |
+ } |
|
| 127 | 130 |
for _, network := range networks {
|
| 128 | 131 |
e.protectedElements.networks[network] = struct{}{}
|
| 129 | 132 |
} |
| ... | ... |
@@ -132,11 +157,17 @@ func (e *Execution) ProtectNetwork(t testingT, networks ...string) {
|
| 132 | 132 |
// ProtectNetworks protects existing networks from being cleaned up at the end |
| 133 | 133 |
// of test runs |
| 134 | 134 |
func ProtectNetworks(t testingT, testEnv *Execution) {
|
| 135 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 136 |
+ ht.Helper() |
|
| 137 |
+ } |
|
| 135 | 138 |
networks := getExistingNetworks(t, testEnv) |
| 136 | 139 |
testEnv.ProtectNetwork(t, networks...) |
| 137 | 140 |
} |
| 138 | 141 |
|
| 139 | 142 |
func getExistingNetworks(t assert.TestingT, testEnv *Execution) []string {
|
| 143 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 144 |
+ ht.Helper() |
|
| 145 |
+ } |
|
| 140 | 146 |
client := testEnv.APIClient() |
| 141 | 147 |
networkList, err := client.NetworkList(context.Background(), types.NetworkListOptions{})
|
| 142 | 148 |
assert.NilError(t, err, "failed to list networks") |
| ... | ... |
@@ -150,6 +181,9 @@ func getExistingNetworks(t assert.TestingT, testEnv *Execution) []string {
|
| 150 | 150 |
|
| 151 | 151 |
// ProtectPlugin adds the specified plugin(s) to be protected in case of clean |
| 152 | 152 |
func (e *Execution) ProtectPlugin(t testingT, plugins ...string) {
|
| 153 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 154 |
+ ht.Helper() |
|
| 155 |
+ } |
|
| 153 | 156 |
for _, plugin := range plugins {
|
| 154 | 157 |
e.protectedElements.plugins[plugin] = struct{}{}
|
| 155 | 158 |
} |
| ... | ... |
@@ -158,11 +192,17 @@ func (e *Execution) ProtectPlugin(t testingT, plugins ...string) {
|
| 158 | 158 |
// ProtectPlugins protects existing plugins from being cleaned up at the end of |
| 159 | 159 |
// test runs |
| 160 | 160 |
func ProtectPlugins(t testingT, testEnv *Execution) {
|
| 161 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 162 |
+ ht.Helper() |
|
| 163 |
+ } |
|
| 161 | 164 |
plugins := getExistingPlugins(t, testEnv) |
| 162 | 165 |
testEnv.ProtectPlugin(t, plugins...) |
| 163 | 166 |
} |
| 164 | 167 |
|
| 165 | 168 |
func getExistingPlugins(t assert.TestingT, testEnv *Execution) []string {
|
| 169 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 170 |
+ ht.Helper() |
|
| 171 |
+ } |
|
| 166 | 172 |
client := testEnv.APIClient() |
| 167 | 173 |
pluginList, err := client.PluginList(context.Background(), filters.Args{})
|
| 168 | 174 |
// Docker EE does not allow cluster-wide plugin management. |
| ... | ... |
@@ -180,6 +220,9 @@ func getExistingPlugins(t assert.TestingT, testEnv *Execution) []string {
|
| 180 | 180 |
|
| 181 | 181 |
// ProtectVolume adds the specified volume(s) to be protected in case of clean |
| 182 | 182 |
func (e *Execution) ProtectVolume(t testingT, volumes ...string) {
|
| 183 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 184 |
+ ht.Helper() |
|
| 185 |
+ } |
|
| 183 | 186 |
for _, volume := range volumes {
|
| 184 | 187 |
e.protectedElements.volumes[volume] = struct{}{}
|
| 185 | 188 |
} |
| ... | ... |
@@ -188,11 +231,17 @@ func (e *Execution) ProtectVolume(t testingT, volumes ...string) {
|
| 188 | 188 |
// ProtectVolumes protects existing volumes from being cleaned up at the end of |
| 189 | 189 |
// test runs |
| 190 | 190 |
func ProtectVolumes(t testingT, testEnv *Execution) {
|
| 191 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 192 |
+ ht.Helper() |
|
| 193 |
+ } |
|
| 191 | 194 |
volumes := getExistingVolumes(t, testEnv) |
| 192 | 195 |
testEnv.ProtectVolume(t, volumes...) |
| 193 | 196 |
} |
| 194 | 197 |
|
| 195 | 198 |
func getExistingVolumes(t assert.TestingT, testEnv *Execution) []string {
|
| 199 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 200 |
+ ht.Helper() |
|
| 201 |
+ } |
|
| 196 | 202 |
client := testEnv.APIClient() |
| 197 | 203 |
volumeList, err := client.VolumeList(context.Background(), filters.Args{})
|
| 198 | 204 |
assert.NilError(t, err, "failed to list volumes") |
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"os" |
| 8 | 8 |
"path/filepath" |
| 9 | 9 |
|
| 10 |
+ "github.com/docker/docker/internal/test" |
|
| 10 | 11 |
"github.com/docker/docker/pkg/archive" |
| 11 | 12 |
) |
| 12 | 13 |
|
| ... | ... |
@@ -17,6 +18,9 @@ type testingT interface {
|
| 17 | 17 |
|
| 18 | 18 |
// New creates a fake build context |
| 19 | 19 |
func New(t testingT, dir string, modifiers ...func(*Fake) error) *Fake {
|
| 20 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 21 |
+ ht.Helper() |
|
| 22 |
+ } |
|
| 20 | 23 |
fakeContext := &Fake{Dir: dir}
|
| 21 | 24 |
if dir == "" {
|
| 22 | 25 |
if err := newDir(fakeContext); err != nil {
|
| ... | ... |
@@ -116,6 +120,9 @@ func (f *Fake) Close() error {
|
| 116 | 116 |
|
| 117 | 117 |
// AsTarReader returns a ReadCloser with the contents of Dir as a tar archive. |
| 118 | 118 |
func (f *Fake) AsTarReader(t testingT) io.ReadCloser {
|
| 119 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 120 |
+ ht.Helper() |
|
| 121 |
+ } |
|
| 119 | 122 |
reader, err := archive.TarWithOptions(f.Dir, &archive.TarOptions{})
|
| 120 | 123 |
if err != nil {
|
| 121 | 124 |
t.Fatalf("Failed to create tar from %s: %s", f.Dir, err)
|
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"os/exec" |
| 10 | 10 |
"path/filepath" |
| 11 | 11 |
|
| 12 |
+ "github.com/docker/docker/internal/test" |
|
| 12 | 13 |
"github.com/docker/docker/internal/test/fakecontext" |
| 13 | 14 |
"github.com/docker/docker/internal/test/fakestorage" |
| 14 | 15 |
"github.com/gotestyourself/gotestyourself/assert" |
| ... | ... |
@@ -63,6 +64,9 @@ func (g *FakeGit) Close() {
|
| 63 | 63 |
|
| 64 | 64 |
// New create a fake git server that can be used for git related tests |
| 65 | 65 |
func New(c testingT, name string, files map[string]string, enforceLocalServer bool) *FakeGit {
|
| 66 |
+ if ht, ok := c.(test.HelperT); ok {
|
|
| 67 |
+ ht.Helper() |
|
| 68 |
+ } |
|
| 66 | 69 |
ctx := fakecontext.New(c, "", fakecontext.WithFiles(files)) |
| 67 | 70 |
defer ctx.Close() |
| 68 | 71 |
curdir, err := os.Getwd() |
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"sync" |
| 11 | 11 |
|
| 12 | 12 |
"github.com/docker/docker/api/types" |
| 13 |
+ "github.com/docker/docker/internal/test" |
|
| 13 | 14 |
"github.com/docker/docker/pkg/archive" |
| 14 | 15 |
"github.com/gotestyourself/gotestyourself/assert" |
| 15 | 16 |
) |
| ... | ... |
@@ -17,6 +18,9 @@ import ( |
| 17 | 17 |
var ensureHTTPServerOnce sync.Once |
| 18 | 18 |
|
| 19 | 19 |
func ensureHTTPServerImage(t testingT) {
|
| 20 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 21 |
+ ht.Helper() |
|
| 22 |
+ } |
|
| 20 | 23 |
var doIt bool |
| 21 | 24 |
ensureHTTPServerOnce.Do(func() {
|
| 22 | 25 |
doIt = true |
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
"github.com/docker/docker/api/types" |
| 15 | 15 |
containertypes "github.com/docker/docker/api/types/container" |
| 16 | 16 |
"github.com/docker/docker/client" |
| 17 |
+ "github.com/docker/docker/internal/test" |
|
| 17 | 18 |
"github.com/docker/docker/internal/test/environment" |
| 18 | 19 |
"github.com/docker/docker/internal/test/fakecontext" |
| 19 | 20 |
"github.com/docker/docker/internal/test/request" |
| ... | ... |
@@ -56,6 +57,9 @@ func SetTestEnvironment(env *environment.Execution) {
|
| 56 | 56 |
|
| 57 | 57 |
// New returns a static file server that will be use as build context. |
| 58 | 58 |
func New(t testingT, dir string, modifiers ...func(*fakecontext.Fake) error) Fake {
|
| 59 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 60 |
+ ht.Helper() |
|
| 61 |
+ } |
|
| 59 | 62 |
if testEnv == nil {
|
| 60 | 63 |
t.Fatal("fakstorage package requires SetTestEnvironment() to be called before use.")
|
| 61 | 64 |
} |
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"path/filepath" |
| 10 | 10 |
"time" |
| 11 | 11 |
|
| 12 |
+ "github.com/docker/docker/internal/test" |
|
| 12 | 13 |
"github.com/gotestyourself/gotestyourself/assert" |
| 13 | 14 |
"github.com/opencontainers/go-digest" |
| 14 | 15 |
) |
| ... | ... |
@@ -54,6 +55,9 @@ type Config struct {
|
| 54 | 54 |
|
| 55 | 55 |
// NewV2 creates a v2 registry server |
| 56 | 56 |
func NewV2(t testingT, ops ...func(*Config)) *V2 {
|
| 57 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 58 |
+ ht.Helper() |
|
| 59 |
+ } |
|
| 57 | 60 |
c := &Config{
|
| 58 | 61 |
registryURL: DefaultURL, |
| 59 | 62 |
} |
| ... | ... |
@@ -135,6 +139,9 @@ http: |
| 135 | 135 |
|
| 136 | 136 |
// WaitReady waits for the registry to be ready to serve requests (or fail after a while) |
| 137 | 137 |
func (r *V2) WaitReady(t testingT) {
|
| 138 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 139 |
+ ht.Helper() |
|
| 140 |
+ } |
|
| 138 | 141 |
var err error |
| 139 | 142 |
for i := 0; i != 50; i++ {
|
| 140 | 143 |
if err = r.Ping(); err == nil {
|
| ... | ... |
@@ -183,6 +190,9 @@ func (r *V2) getBlobFilename(blobDigest digest.Digest) string {
|
| 183 | 183 |
|
| 184 | 184 |
// ReadBlobContents read the file corresponding to the specified digest |
| 185 | 185 |
func (r *V2) ReadBlobContents(t assert.TestingT, blobDigest digest.Digest) []byte {
|
| 186 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 187 |
+ ht.Helper() |
|
| 188 |
+ } |
|
| 186 | 189 |
// Load the target manifest blob. |
| 187 | 190 |
manifestBlob, err := ioutil.ReadFile(r.getBlobFilename(blobDigest)) |
| 188 | 191 |
assert.NilError(t, err, "unable to read blob") |
| ... | ... |
@@ -191,6 +201,9 @@ func (r *V2) ReadBlobContents(t assert.TestingT, blobDigest digest.Digest) []byt |
| 191 | 191 |
|
| 192 | 192 |
// WriteBlobContents write the file corresponding to the specified digest with the given content |
| 193 | 193 |
func (r *V2) WriteBlobContents(t assert.TestingT, blobDigest digest.Digest, data []byte) {
|
| 194 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 195 |
+ ht.Helper() |
|
| 196 |
+ } |
|
| 194 | 197 |
err := ioutil.WriteFile(r.getBlobFilename(blobDigest), data, os.FileMode(0644)) |
| 195 | 198 |
assert.NilError(t, err, "unable to write malicious data blob") |
| 196 | 199 |
} |
| ... | ... |
@@ -198,6 +211,9 @@ func (r *V2) WriteBlobContents(t assert.TestingT, blobDigest digest.Digest, data |
| 198 | 198 |
// TempMoveBlobData moves the existing data file aside, so that we can replace it with a |
| 199 | 199 |
// malicious blob of data for example. |
| 200 | 200 |
func (r *V2) TempMoveBlobData(t testingT, blobDigest digest.Digest) (undo func()) {
|
| 201 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 202 |
+ ht.Helper() |
|
| 203 |
+ } |
|
| 201 | 204 |
tempFile, err := ioutil.TempFile("", "registry-temp-blob-")
|
| 202 | 205 |
assert.NilError(t, err, "unable to get temporary blob file") |
| 203 | 206 |
tempFile.Close() |
| ... | ... |
@@ -6,6 +6,8 @@ import ( |
| 6 | 6 |
"regexp" |
| 7 | 7 |
"strings" |
| 8 | 8 |
"sync" |
| 9 |
+ |
|
| 10 |
+ "github.com/docker/docker/internal/test" |
|
| 9 | 11 |
) |
| 10 | 12 |
|
| 11 | 13 |
type handlerFunc func(w http.ResponseWriter, r *http.Request) |
| ... | ... |
@@ -27,6 +29,9 @@ func (tr *Mock) RegisterHandler(path string, h handlerFunc) {
|
| 27 | 27 |
|
| 28 | 28 |
// NewMock creates a registry mock |
| 29 | 29 |
func NewMock(t testingT) (*Mock, error) {
|
| 30 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 31 |
+ ht.Helper() |
|
| 32 |
+ } |
|
| 30 | 33 |
testReg := &Mock{handlers: make(map[string]handlerFunc)}
|
| 31 | 34 |
|
| 32 | 35 |
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
"time" |
| 15 | 15 |
|
| 16 | 16 |
"github.com/docker/docker/client" |
| 17 |
+ "github.com/docker/docker/internal/test" |
|
| 17 | 18 |
"github.com/docker/docker/internal/test/environment" |
| 18 | 19 |
"github.com/docker/docker/opts" |
| 19 | 20 |
"github.com/docker/docker/pkg/ioutils" |
| ... | ... |
@@ -25,6 +26,9 @@ import ( |
| 25 | 25 |
|
| 26 | 26 |
// NewAPIClient returns a docker API client configured from environment variables |
| 27 | 27 |
func NewAPIClient(t assert.TestingT, ops ...func(*client.Client) error) client.APIClient {
|
| 28 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 29 |
+ ht.Helper() |
|
| 30 |
+ } |
|
| 28 | 31 |
ops = append([]func(*client.Client) error{client.FromEnv}, ops...)
|
| 29 | 32 |
clt, err := client.NewClientWithOpts(ops...) |
| 30 | 33 |
assert.NilError(t, err) |
| ... | ... |
@@ -33,6 +37,9 @@ func NewAPIClient(t assert.TestingT, ops ...func(*client.Client) error) client.A |
| 33 | 33 |
|
| 34 | 34 |
// DaemonTime provides the current time on the daemon host |
| 35 | 35 |
func DaemonTime(ctx context.Context, t assert.TestingT, client client.APIClient, testEnv *environment.Execution) time.Time {
|
| 36 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 37 |
+ ht.Helper() |
|
| 38 |
+ } |
|
| 36 | 39 |
if testEnv.IsLocalDaemon() {
|
| 37 | 40 |
return time.Now() |
| 38 | 41 |
} |
| ... | ... |
@@ -48,6 +55,9 @@ func DaemonTime(ctx context.Context, t assert.TestingT, client client.APIClient, |
| 48 | 48 |
// DaemonUnixTime returns the current time on the daemon host with nanoseconds precision. |
| 49 | 49 |
// It return the time formatted how the client sends timestamps to the server. |
| 50 | 50 |
func DaemonUnixTime(ctx context.Context, t assert.TestingT, client client.APIClient, testEnv *environment.Execution) string {
|
| 51 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 52 |
+ ht.Helper() |
|
| 53 |
+ } |
|
| 51 | 54 |
dt := DaemonTime(ctx, t, client, testEnv) |
| 52 | 55 |
return fmt.Sprintf("%d.%09d", dt.Unix(), int64(dt.Nanosecond()))
|
| 53 | 56 |
} |