Parcourir la source

"Assert change"

Signed-off-by: GoBella <caili_welcome@163.com>
GoBella il y a 9 ans
Parent
commit
c16dd88c5e
1 fichiers modifiés avec 34 ajouts et 97 suppressions
  1. 34 97
      integration-cli/docker_cli_pull_trusted_test.go

+ 34 - 97
integration-cli/docker_cli_pull_trusted_test.go

@@ -4,9 +4,9 @@ import (
 	"fmt"
 	"fmt"
 	"io/ioutil"
 	"io/ioutil"
 	"os/exec"
 	"os/exec"
-	"strings"
 	"time"
 	"time"
 
 
+	"github.com/docker/docker/pkg/integration/checker"
 	"github.com/go-check/check"
 	"github.com/go-check/check"
 )
 )
 
 
@@ -17,27 +17,18 @@ func (s *DockerTrustSuite) TestTrustedPull(c *check.C) {
 	pullCmd := exec.Command(dockerBinary, "pull", repoName)
 	pullCmd := exec.Command(dockerBinary, "pull", repoName)
 	s.trustedCmd(pullCmd)
 	s.trustedCmd(pullCmd)
 	out, _, err := runCommandWithOutput(pullCmd)
 	out, _, err := runCommandWithOutput(pullCmd)
-	if err != nil {
-		c.Fatalf("Error running trusted pull: %s\n%s", err, out)
-	}
 
 
-	if !strings.Contains(string(out), "Tagging") {
-		c.Fatalf("Missing expected output on trusted pull:\n%s", out)
-	}
+	c.Assert(err, check.IsNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out))
 
 
 	dockerCmd(c, "rmi", repoName)
 	dockerCmd(c, "rmi", repoName)
-
 	// Try untrusted pull to ensure we pushed the tag to the registry
 	// Try untrusted pull to ensure we pushed the tag to the registry
 	pullCmd = exec.Command(dockerBinary, "pull", "--disable-content-trust=true", repoName)
 	pullCmd = exec.Command(dockerBinary, "pull", "--disable-content-trust=true", repoName)
 	s.trustedCmd(pullCmd)
 	s.trustedCmd(pullCmd)
 	out, _, err = runCommandWithOutput(pullCmd)
 	out, _, err = runCommandWithOutput(pullCmd)
-	if err != nil {
-		c.Fatalf("Error running trusted pull: %s\n%s", err, out)
-	}
+	c.Assert(err, check.IsNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
 
 
-	if !strings.Contains(string(out), "Status: Downloaded") {
-		c.Fatalf("Missing expected output on trusted pull with --disable-content-trust:\n%s", out)
-	}
 }
 }
 
 
 func (s *DockerTrustSuite) TestTrustedIsolatedPull(c *check.C) {
 func (s *DockerTrustSuite) TestTrustedIsolatedPull(c *check.C) {
@@ -47,13 +38,9 @@ func (s *DockerTrustSuite) TestTrustedIsolatedPull(c *check.C) {
 	pullCmd := exec.Command(dockerBinary, "--config", "/tmp/docker-isolated", "pull", repoName)
 	pullCmd := exec.Command(dockerBinary, "--config", "/tmp/docker-isolated", "pull", repoName)
 	s.trustedCmd(pullCmd)
 	s.trustedCmd(pullCmd)
 	out, _, err := runCommandWithOutput(pullCmd)
 	out, _, err := runCommandWithOutput(pullCmd)
-	if err != nil {
-		c.Fatalf("Error running trusted pull: %s\n%s", err, out)
-	}
 
 
-	if !strings.Contains(string(out), "Tagging") {
-		c.Fatalf("Missing expected output on trusted pull:\n%s", out)
-	}
+	c.Assert(err, check.IsNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(string(out)))
 
 
 	dockerCmd(c, "rmi", repoName)
 	dockerCmd(c, "rmi", repoName)
 }
 }
@@ -69,13 +56,9 @@ func (s *DockerTrustSuite) TestUntrustedPull(c *check.C) {
 	pullCmd := exec.Command(dockerBinary, "pull", repoName)
 	pullCmd := exec.Command(dockerBinary, "pull", repoName)
 	s.trustedCmd(pullCmd)
 	s.trustedCmd(pullCmd)
 	out, _, err := runCommandWithOutput(pullCmd)
 	out, _, err := runCommandWithOutput(pullCmd)
-	if err == nil {
-		c.Fatalf("Error expected when running trusted pull with:\n%s", out)
-	}
 
 
-	if !strings.Contains(string(out), "no trust data available") {
-		c.Fatalf("Missing expected output on trusted pull:\n%s", out)
-	}
+	c.Assert(err, check.NotNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "no trust data available", check.Commentf(out))
 }
 }
 
 
 func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
 func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
@@ -90,13 +73,9 @@ func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
 		pullCmd := exec.Command(dockerBinary, "pull", repoName)
 		pullCmd := exec.Command(dockerBinary, "pull", repoName)
 		s.trustedCmd(pullCmd)
 		s.trustedCmd(pullCmd)
 		out, _, err := runCommandWithOutput(pullCmd)
 		out, _, err := runCommandWithOutput(pullCmd)
-		if err == nil {
-			c.Fatalf("Error running trusted pull in the distant future: %s\n%s", err, out)
-		}
 
 
-		if !strings.Contains(string(out), "could not validate the path to a trusted root") {
-			c.Fatalf("Missing expected output on trusted pull in the distant future:\n%s", out)
-		}
+		c.Assert(err, check.NotNil, check.Commentf(out))
+		c.Assert(string(out), checker.Contains, "could not validate the path to a trusted root", check.Commentf(out))
 	})
 	})
 
 
 	runAtDifferentDate(elevenYearsFromNow, func() {
 	runAtDifferentDate(elevenYearsFromNow, func() {
@@ -104,13 +83,9 @@ func (s *DockerTrustSuite) TestPullWhenCertExpired(c *check.C) {
 		pullCmd := exec.Command(dockerBinary, "pull", "--disable-content-trust", repoName)
 		pullCmd := exec.Command(dockerBinary, "pull", "--disable-content-trust", repoName)
 		s.trustedCmd(pullCmd)
 		s.trustedCmd(pullCmd)
 		out, _, err := runCommandWithOutput(pullCmd)
 		out, _, err := runCommandWithOutput(pullCmd)
-		if err != nil {
-			c.Fatalf("Error running untrusted pull in the distant future: %s\n%s", err, out)
-		}
 
 
-		if !strings.Contains(string(out), "Status: Downloaded") {
-			c.Fatalf("Missing expected output on untrusted pull in the distant future:\n%s", out)
-		}
+		c.Assert(err, check.IsNil, check.Commentf(out))
+		c.Assert(string(out), checker.Contains, "Status: Downloaded", check.Commentf(out))
 	})
 	})
 }
 }
 
 
@@ -127,35 +102,25 @@ func (s *DockerTrustSuite) TestTrustedPullFromBadTrustServer(c *check.C) {
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
 	s.trustedCmd(pushCmd)
 	s.trustedCmd(pushCmd)
 	out, _, err := runCommandWithOutput(pushCmd)
 	out, _, err := runCommandWithOutput(pushCmd)
-	if err != nil {
-		c.Fatalf("Error running trusted push: %s\n%s", err, out)
-	}
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
-	}
 
 
+	c.Assert(err, check.IsNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf(out))
 	dockerCmd(c, "rmi", repoName)
 	dockerCmd(c, "rmi", repoName)
 
 
 	// Try pull
 	// Try pull
 	pullCmd := exec.Command(dockerBinary, "pull", repoName)
 	pullCmd := exec.Command(dockerBinary, "pull", repoName)
 	s.trustedCmd(pullCmd)
 	s.trustedCmd(pullCmd)
 	out, _, err = runCommandWithOutput(pullCmd)
 	out, _, err = runCommandWithOutput(pullCmd)
-	if err != nil {
-		c.Fatalf("Error running trusted pull: %s\n%s", err, out)
-	}
-
-	if !strings.Contains(string(out), "Tagging") {
-		c.Fatalf("Missing expected output on trusted pull:\n%s", out)
-	}
 
 
+	c.Assert(err, check.IsNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out))
 	dockerCmd(c, "rmi", repoName)
 	dockerCmd(c, "rmi", repoName)
 
 
 	// Kill the notary server, start a new "evil" one.
 	// Kill the notary server, start a new "evil" one.
 	s.not.Close()
 	s.not.Close()
 	s.not, err = newTestNotary(c)
 	s.not, err = newTestNotary(c)
-	if err != nil {
-		c.Fatalf("Restarting notary server failed.")
-	}
+
+	c.Assert(err, check.IsNil, check.Commentf("Restarting notary server failed."))
 
 
 	// In order to make an evil server, lets re-init a client (with a different trust dir) and push new data.
 	// In order to make an evil server, lets re-init a client (with a different trust dir) and push new data.
 	// tag an image and upload it to the private registry
 	// tag an image and upload it to the private registry
@@ -165,24 +130,17 @@ func (s *DockerTrustSuite) TestTrustedPullFromBadTrustServer(c *check.C) {
 	pushCmd = exec.Command(dockerBinary, "--config", evilLocalConfigDir, "push", repoName)
 	pushCmd = exec.Command(dockerBinary, "--config", evilLocalConfigDir, "push", repoName)
 	s.trustedCmd(pushCmd)
 	s.trustedCmd(pushCmd)
 	out, _, err = runCommandWithOutput(pushCmd)
 	out, _, err = runCommandWithOutput(pushCmd)
-	if err != nil {
-		c.Fatalf("Error running trusted push: %s\n%s", err, out)
-	}
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
-	}
+
+	c.Assert(err, check.IsNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf(out))
 
 
 	// Now, try pulling with the original client from this new trust server. This should fail.
 	// Now, try pulling with the original client from this new trust server. This should fail.
 	pullCmd = exec.Command(dockerBinary, "pull", repoName)
 	pullCmd = exec.Command(dockerBinary, "pull", repoName)
 	s.trustedCmd(pullCmd)
 	s.trustedCmd(pullCmd)
 	out, _, err = runCommandWithOutput(pullCmd)
 	out, _, err = runCommandWithOutput(pullCmd)
-	if err == nil {
-		c.Fatalf("Expected to fail on this pull due to different remote data: %s\n%s", err, out)
-	}
 
 
-	if !strings.Contains(string(out), "failed to validate data with current trusted certificates") {
-		c.Fatalf("Missing expected output on trusted pull:\n%s", out)
-	}
+	c.Assert(err, check.NotNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "failed to validate data with current trusted certificates", check.Commentf(out))
 }
 }
 
 
 func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) {
 func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) {
@@ -195,13 +153,9 @@ func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) {
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
 	pushCmd := exec.Command(dockerBinary, "push", repoName)
 	s.trustedCmd(pushCmd)
 	s.trustedCmd(pushCmd)
 	out, _, err := runCommandWithOutput(pushCmd)
 	out, _, err := runCommandWithOutput(pushCmd)
-	if err != nil {
-		c.Fatalf("trusted push failed: %s\n%s", err, out)
-	}
 
 
-	if !strings.Contains(string(out), "Signing and pushing trust metadata") {
-		c.Fatalf("Missing expected output on trusted push:\n%s", out)
-	}
+	c.Assert(err, check.IsNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "Signing and pushing trust metadata", check.Commentf(out))
 
 
 	dockerCmd(c, "rmi", repoName)
 	dockerCmd(c, "rmi", repoName)
 
 
@@ -213,13 +167,9 @@ func (s *DockerTrustSuite) TestTrustedPullWithExpiredSnapshot(c *check.C) {
 		pullCmd := exec.Command(dockerBinary, "pull", repoName)
 		pullCmd := exec.Command(dockerBinary, "pull", repoName)
 		s.trustedCmd(pullCmd)
 		s.trustedCmd(pullCmd)
 		out, _, err = runCommandWithOutput(pullCmd)
 		out, _, err = runCommandWithOutput(pullCmd)
-		if err == nil {
-			c.Fatalf("Missing expected error running trusted pull with expired snapshots")
-		}
 
 
-		if !strings.Contains(string(out), "repository out-of-date") {
-			c.Fatalf("Missing expected output on trusted pull with expired snapshot:\n%s", out)
-		}
+		c.Assert(err, check.NotNil, check.Commentf("Missing expected error running trusted pull with expired snapshots"))
+		c.Assert(string(out), checker.Contains, "repository out-of-date", check.Commentf(out))
 	})
 	})
 }
 }
 
 
@@ -229,25 +179,16 @@ func (s *DockerTrustSuite) TestTrustedOfflinePull(c *check.C) {
 	pullCmd := exec.Command(dockerBinary, "pull", repoName)
 	pullCmd := exec.Command(dockerBinary, "pull", repoName)
 	s.trustedCmdWithServer(pullCmd, "https://invalidnotaryserver")
 	s.trustedCmdWithServer(pullCmd, "https://invalidnotaryserver")
 	out, _, err := runCommandWithOutput(pullCmd)
 	out, _, err := runCommandWithOutput(pullCmd)
-	if err == nil {
-		c.Fatalf("Expected error pulling with invalid notary server:\n%s", out)
-	}
-
-	if !strings.Contains(string(out), "error contacting notary server") {
-		c.Fatalf("Missing expected output on trusted pull:\n%s", out)
-	}
 
 
+	c.Assert(err, check.NotNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "error contacting notary server", check.Commentf(out))
 	// Do valid trusted pull to warm cache
 	// Do valid trusted pull to warm cache
 	pullCmd = exec.Command(dockerBinary, "pull", repoName)
 	pullCmd = exec.Command(dockerBinary, "pull", repoName)
 	s.trustedCmd(pullCmd)
 	s.trustedCmd(pullCmd)
 	out, _, err = runCommandWithOutput(pullCmd)
 	out, _, err = runCommandWithOutput(pullCmd)
-	if err != nil {
-		c.Fatalf("Error running trusted pull: %s\n%s", err, out)
-	}
 
 
-	if !strings.Contains(string(out), "Tagging") {
-		c.Fatalf("Missing expected output on trusted pull:\n%s", out)
-	}
+	c.Assert(err, check.IsNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out))
 
 
 	dockerCmd(c, "rmi", repoName)
 	dockerCmd(c, "rmi", repoName)
 
 
@@ -255,11 +196,7 @@ func (s *DockerTrustSuite) TestTrustedOfflinePull(c *check.C) {
 	pullCmd = exec.Command(dockerBinary, "pull", repoName)
 	pullCmd = exec.Command(dockerBinary, "pull", repoName)
 	s.trustedCmdWithServer(pullCmd, "https://invalidnotaryserver")
 	s.trustedCmdWithServer(pullCmd, "https://invalidnotaryserver")
 	out, _, err = runCommandWithOutput(pullCmd)
 	out, _, err = runCommandWithOutput(pullCmd)
-	if err != nil {
-		c.Fatalf("Error running trusted pull: %s\n%s", err, out)
-	}
 
 
-	if !strings.Contains(string(out), "Tagging") {
-		c.Fatalf("Missing expected output on trusted pull:\n%s", out)
-	}
+	c.Assert(err, check.IsNil, check.Commentf(out))
+	c.Assert(string(out), checker.Contains, "Tagging", check.Commentf(out))
 }
 }