Browse code

TestBuildNotVerboseFailureRemote: fix false positive

I got the following test failure on power:

10:00:56
10:00:56
----------------------------------------------------------------------
10:00:56 FAIL: docker_cli_build_test.go:3521:
DockerSuite.TestBuildNotVerboseFailureRemote
10:00:56
10:00:56 docker_cli_build_test.go:3536:
10:00:56 c.Fatal(fmt.Errorf("Test[%s] expected that quiet stderr and
verbose stdout are equal; quiet [%v], verbose [%v]", name,
quietResult.Stderr(), result.Combined()))
10:00:56 ... Error: Test[quiet_build_wrong_remote] expected that quiet
stderr and verbose stdout are equal; quiet [
10:00:56 unable to prepare context: unable to download remote context
http://something.invalid: Get http://something.invalid: dial tcp: lookup
something.invalid on 172.29.128.11:53: no such host
10:00:56 ], verbose [unable to prepare context: unable to download
remote context http://something.invalid: Get http://something.invalid:
dial tcp: lookup something.invalid on 8.8.8.8:53: no such host
10:00:56 ]
10:00:56
10:00:56
10:00:56
----------------------------------------------------------------------

The reason is, either more than one name server is configured, or
nameserver was reconfigured in the middle of the test run. In any case,
different nameserver IP in an error messages should not be treated
as a failure, so let's strip those out.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2017/12/06 04:25:37
Showing 1 changed files
... ...
@@ -3532,7 +3532,17 @@ func (s *DockerSuite) TestBuildNotVerboseFailureRemote(c *check.C) {
3532 3532
 	result.Assert(c, icmd.Expected{
3533 3533
 		ExitCode: 1,
3534 3534
 	})
3535
-	if strings.TrimSpace(quietResult.Stderr()) != strings.TrimSpace(result.Combined()) {
3535
+
3536
+	// An error message should contain name server IP and port, like this:
3537
+	//  "dial tcp: lookup something.invalid on 172.29.128.11:53: no such host"
3538
+	// The IP:port need to be removed in order to not trigger a test failur
3539
+	// when more than one nameserver is configured.
3540
+	// While at it, also strip excessive newlines.
3541
+	normalize := func(msg string) string {
3542
+		return strings.TrimSpace(regexp.MustCompile("[1-9][0-9.]+:[0-9]+").ReplaceAllLiteralString(msg, "<ip:port>"))
3543
+	}
3544
+
3545
+	if normalize(quietResult.Stderr()) != normalize(result.Combined()) {
3536 3546
 		c.Fatal(fmt.Errorf("Test[%s] expected that quiet stderr and verbose stdout are equal; quiet [%v], verbose [%v]", name, quietResult.Stderr(), result.Combined()))
3537 3547
 	}
3538 3548
 }