Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit bad6f3bf738806a5e24c39124506c670fec69f31)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -50,11 +50,13 @@ func dockerCmdWithResult(args ...string) *icmd.Result {
|
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 | 52 |
func findContainerIP(c *testing.T, id string, network string) string {
|
| 53 |
+ c.Helper() |
|
| 53 | 54 |
out, _ := dockerCmd(c, "inspect", fmt.Sprintf("--format='{{ .NetworkSettings.Networks.%s.IPAddress }}'", network), id)
|
| 54 | 55 |
return strings.Trim(out, " \r\n'") |
| 55 | 56 |
} |
| 56 | 57 |
|
| 57 | 58 |
func getContainerCount(c *testing.T) int {
|
| 59 |
+ c.Helper() |
|
| 58 | 60 |
const containers = "Containers:" |
| 59 | 61 |
|
| 60 | 62 |
result := icmd.RunCommand(dockerBinary, "info") |
| ... | ... |
@@ -75,6 +77,7 @@ func getContainerCount(c *testing.T) int {
|
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 | 77 |
func inspectFieldAndUnmarshall(c *testing.T, name, field string, output interface{}) {
|
| 78 |
+ c.Helper() |
|
| 78 | 79 |
str := inspectFieldJSON(c, name, field) |
| 79 | 80 |
err := json.Unmarshal([]byte(str), output) |
| 80 | 81 |
if c != nil {
|
| ... | ... |
@@ -99,6 +102,7 @@ func inspectFieldWithError(name, field string) (string, error) {
|
| 99 | 99 |
|
| 100 | 100 |
// Deprecated: use cli.Inspect |
| 101 | 101 |
func inspectField(c *testing.T, name, field string) string {
|
| 102 |
+ c.Helper() |
|
| 102 | 103 |
out, err := inspectFilter(name, fmt.Sprintf(".%s", field))
|
| 103 | 104 |
if c != nil {
|
| 104 | 105 |
assert.NilError(c, err) |
| ... | ... |
@@ -108,6 +112,7 @@ func inspectField(c *testing.T, name, field string) string {
|
| 108 | 108 |
|
| 109 | 109 |
// Deprecated: use cli.Inspect |
| 110 | 110 |
func inspectFieldJSON(c *testing.T, name, field string) string {
|
| 111 |
+ c.Helper() |
|
| 111 | 112 |
out, err := inspectFilter(name, fmt.Sprintf("json .%s", field))
|
| 112 | 113 |
if c != nil {
|
| 113 | 114 |
assert.NilError(c, err) |
| ... | ... |
@@ -117,6 +122,7 @@ func inspectFieldJSON(c *testing.T, name, field string) string {
|
| 117 | 117 |
|
| 118 | 118 |
// Deprecated: use cli.Inspect |
| 119 | 119 |
func inspectFieldMap(c *testing.T, name, path, field string) string {
|
| 120 |
+ c.Helper() |
|
| 120 | 121 |
out, err := inspectFilter(name, fmt.Sprintf("index .%s %q", path, field))
|
| 121 | 122 |
if c != nil {
|
| 122 | 123 |
assert.NilError(c, err) |
| ... | ... |
@@ -169,6 +175,7 @@ func inspectMountPointJSON(j, destination string) (types.MountPoint, error) {
|
| 169 | 169 |
|
| 170 | 170 |
// Deprecated: use cli.Inspect |
| 171 | 171 |
func inspectImage(c *testing.T, name, filter string) string {
|
| 172 |
+ c.Helper() |
|
| 172 | 173 |
args := []string{"inspect", "--type", "image"}
|
| 173 | 174 |
if filter != "" {
|
| 174 | 175 |
format := fmt.Sprintf("{{%s}}", filter)
|
| ... | ... |
@@ -181,6 +188,7 @@ func inspectImage(c *testing.T, name, filter string) string {
|
| 181 | 181 |
} |
| 182 | 182 |
|
| 183 | 183 |
func getIDByName(c *testing.T, name string) string {
|
| 184 |
+ c.Helper() |
|
| 184 | 185 |
id, err := inspectFieldWithError(name, "Id") |
| 185 | 186 |
assert.NilError(c, err) |
| 186 | 187 |
return id |
| ... | ... |
@@ -188,6 +196,7 @@ func getIDByName(c *testing.T, name string) string {
|
| 188 | 188 |
|
| 189 | 189 |
// Deprecated: use cli.Build |
| 190 | 190 |
func buildImageSuccessfully(c *testing.T, name string, cmdOperators ...cli.CmdOperator) {
|
| 191 |
+ c.Helper() |
|
| 191 | 192 |
buildImage(name, cmdOperators...).Assert(c, icmd.Success) |
| 192 | 193 |
} |
| 193 | 194 |
|
| ... | ... |
@@ -201,6 +210,7 @@ func buildImage(name string, cmdOperators ...cli.CmdOperator) *icmd.Result {
|
| 201 | 201 |
// The file is truncated if it already exists. |
| 202 | 202 |
// Fail the test when error occurs. |
| 203 | 203 |
func writeFile(dst, content string, c *testing.T) {
|
| 204 |
+ c.Helper() |
|
| 204 | 205 |
// Create subdirectories if necessary |
| 205 | 206 |
assert.Assert(c, os.MkdirAll(path.Dir(dst), 0700) == nil) |
| 206 | 207 |
f, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0700) |
| ... | ... |
@@ -214,6 +224,7 @@ func writeFile(dst, content string, c *testing.T) {
|
| 214 | 214 |
// Return the contents of file at path `src`. |
| 215 | 215 |
// Fail the test when error occurs. |
| 216 | 216 |
func readFile(src string, c *testing.T) (content string) {
|
| 217 |
+ c.Helper() |
|
| 217 | 218 |
data, err := ioutil.ReadFile(src) |
| 218 | 219 |
assert.NilError(c, err) |
| 219 | 220 |
|
| ... | ... |
@@ -226,6 +237,7 @@ func containerStorageFile(containerID, basename string) string {
|
| 226 | 226 |
|
| 227 | 227 |
// docker commands that use this function must be run with the '-d' switch. |
| 228 | 228 |
func runCommandAndReadContainerFile(c *testing.T, filename string, command string, args ...string) []byte {
|
| 229 |
+ c.Helper() |
|
| 229 | 230 |
result := icmd.RunCommand(command, args...) |
| 230 | 231 |
result.Assert(c, icmd.Success) |
| 231 | 232 |
contID := strings.TrimSpace(result.Combined()) |
| ... | ... |
@@ -236,6 +248,7 @@ func runCommandAndReadContainerFile(c *testing.T, filename string, command strin |
| 236 | 236 |
} |
| 237 | 237 |
|
| 238 | 238 |
func readContainerFile(c *testing.T, containerID, filename string) []byte {
|
| 239 |
+ c.Helper() |
|
| 239 | 240 |
f, err := os.Open(containerStorageFile(containerID, filename)) |
| 240 | 241 |
assert.NilError(c, err) |
| 241 | 242 |
defer f.Close() |
| ... | ... |
@@ -246,6 +259,7 @@ func readContainerFile(c *testing.T, containerID, filename string) []byte {
|
| 246 | 246 |
} |
| 247 | 247 |
|
| 248 | 248 |
func readContainerFileWithExec(c *testing.T, containerID, filename string) []byte {
|
| 249 |
+ c.Helper() |
|
| 249 | 250 |
result := icmd.RunCommand(dockerBinary, "exec", containerID, "cat", filename) |
| 250 | 251 |
result.Assert(c, icmd.Success) |
| 251 | 252 |
return []byte(result.Combined()) |
| ... | ... |
@@ -253,6 +267,7 @@ func readContainerFileWithExec(c *testing.T, containerID, filename string) []byt |
| 253 | 253 |
|
| 254 | 254 |
// daemonTime provides the current time on the daemon host |
| 255 | 255 |
func daemonTime(c *testing.T) time.Time {
|
| 256 |
+ c.Helper() |
|
| 256 | 257 |
if testEnv.IsLocalDaemon() {
|
| 257 | 258 |
return time.Now() |
| 258 | 259 |
} |
| ... | ... |
@@ -271,6 +286,7 @@ func daemonTime(c *testing.T) time.Time {
|
| 271 | 271 |
// daemonUnixTime returns the current time on the daemon host with nanoseconds precision. |
| 272 | 272 |
// It return the time formatted how the client sends timestamps to the server. |
| 273 | 273 |
func daemonUnixTime(c *testing.T) string {
|
| 274 |
+ c.Helper() |
|
| 274 | 275 |
return parseEventTime(daemonTime(c)) |
| 275 | 276 |
} |
| 276 | 277 |
|
| ... | ... |
@@ -306,6 +322,7 @@ func appendBaseEnv(isTLS bool, env ...string) []string {
|
| 306 | 306 |
} |
| 307 | 307 |
|
| 308 | 308 |
func createTmpFile(c *testing.T, content string) string {
|
| 309 |
+ c.Helper() |
|
| 309 | 310 |
f, err := ioutil.TempFile("", "testfile")
|
| 310 | 311 |
assert.NilError(c, err) |
| 311 | 312 |
|
| ... | ... |
@@ -337,6 +354,7 @@ func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg |
| 337 | 337 |
} |
| 338 | 338 |
|
| 339 | 339 |
func getInspectBody(c *testing.T, version, id string) []byte {
|
| 340 |
+ c.Helper() |
|
| 340 | 341 |
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion(version)) |
| 341 | 342 |
assert.NilError(c, err) |
| 342 | 343 |
defer cli.Close() |
| ... | ... |
@@ -348,12 +366,14 @@ func getInspectBody(c *testing.T, version, id string) []byte {
|
| 348 | 348 |
// Run a long running idle task in a background container using the |
| 349 | 349 |
// system-specific default image and command. |
| 350 | 350 |
func runSleepingContainer(c *testing.T, extraArgs ...string) string {
|
| 351 |
+ c.Helper() |
|
| 351 | 352 |
return runSleepingContainerInImage(c, "busybox", extraArgs...) |
| 352 | 353 |
} |
| 353 | 354 |
|
| 354 | 355 |
// Run a long running idle task in a background container using the specified |
| 355 | 356 |
// image and the system-specific command. |
| 356 | 357 |
func runSleepingContainerInImage(c *testing.T, image string, extraArgs ...string) string {
|
| 358 |
+ c.Helper() |
|
| 357 | 359 |
args := []string{"run", "-d"}
|
| 358 | 360 |
args = append(args, extraArgs...) |
| 359 | 361 |
args = append(args, image) |
| ... | ... |
@@ -408,6 +428,7 @@ func waitForGoroutines(expected int) error {
|
| 408 | 408 |
|
| 409 | 409 |
// getErrorMessage returns the error message from an error API response |
| 410 | 410 |
func getErrorMessage(c *testing.T, body []byte) string {
|
| 411 |
+ c.Helper() |
|
| 411 | 412 |
var resp types.ErrorResponse |
| 412 | 413 |
assert.Assert(c, json.Unmarshal(body, &resp) == nil) |
| 413 | 414 |
return strings.TrimSpace(resp.Message) |
| ... | ... |
@@ -418,6 +439,7 @@ type reducer func(...interface{}) interface{}
|
| 418 | 418 |
|
| 419 | 419 |
func pollCheck(t *testing.T, f checkF, compare func(x interface{}) assert.BoolOrComparison) poll.Check {
|
| 420 | 420 |
return func(poll.LogT) poll.Result {
|
| 421 |
+ t.Helper() |
|
| 421 | 422 |
v, comment := f(t) |
| 422 | 423 |
if assert.Check(t, compare(v)) {
|
| 423 | 424 |
return poll.Success() |
| ... | ... |
@@ -428,6 +450,7 @@ func pollCheck(t *testing.T, f checkF, compare func(x interface{}) assert.BoolOr
|
| 428 | 428 |
|
| 429 | 429 |
func reducedCheck(r reducer, funcs ...checkF) checkF {
|
| 430 | 430 |
return func(c *testing.T) (interface{}, string) {
|
| 431 |
+ c.Helper() |
|
| 431 | 432 |
var values []interface{}
|
| 432 | 433 |
var comments []string |
| 433 | 434 |
for _, f := range funcs {
|