本文整理汇总了Golang中github.com/go-check/check.Commentf函数的典型用法代码示例。如果您正苦于以下问题:Golang Commentf函数的具体用法?Golang Commentf怎么用?Golang Commentf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Commentf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestEventsRedirectStdout
// #5979
func (s *DockerSuite) TestEventsRedirectStdout(c *check.C) {
since := daemonTime(c).Unix()
dockerCmd(c, "run", "busybox", "true")
file, err := ioutil.TempFile("", "")
c.Assert(err, checker.IsNil, check.Commentf("could not create temp file"))
defer os.Remove(file.Name())
command := fmt.Sprintf("%s events --since=%d --until=%d > %s", dockerBinary, since, daemonTime(c).Unix(), file.Name())
_, tty, err := pty.Open()
c.Assert(err, checker.IsNil, check.Commentf("Could not open pty"))
cmd := exec.Command("sh", "-c", command)
cmd.Stdin = tty
cmd.Stdout = tty
cmd.Stderr = tty
c.Assert(cmd.Run(), checker.IsNil, check.Commentf("run err for command %q", command))
scanner := bufio.NewScanner(file)
for scanner.Scan() {
for _, ch := range scanner.Text() {
c.Assert(unicode.IsControl(ch), checker.False, check.Commentf("found control character %v", []byte(string(ch))))
}
}
c.Assert(scanner.Err(), checker.IsNil, check.Commentf("Scan err for command %q", command))
}
示例2: TestTrustedPushWithExpiredTimestamp
func (s *DockerTrustSuite) TestTrustedPushWithExpiredTimestamp(c *check.C) {
c.Skip("Currently changes system time, causing instability")
repoName := fmt.Sprintf("%v/dockercliexpiredtimestamppush/trusted:latest", privateRegistryURL)
// tag the image and upload it to the private registry
dockerCmd(c, "tag", "busybox", repoName)
// Push with default passphrases
pushCmd := exec.Command(dockerBinary, "push", repoName)
s.trustedCmd(pushCmd)
out, _, err := runCommandWithOutput(pushCmd)
c.Assert(err, check.IsNil, check.Commentf("trusted push failed: %s\n%s", err, out))
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push"))
// The timestamps expire in two weeks. Lets check three
threeWeeksLater := time.Now().Add(time.Hour * 24 * 21)
// Should succeed because the server transparently re-signs one
runAtDifferentDate(threeWeeksLater, func() {
pushCmd := exec.Command(dockerBinary, "push", repoName)
s.trustedCmd(pushCmd)
out, _, err := runCommandWithOutput(pushCmd)
c.Assert(err, check.IsNil, check.Commentf("Error running trusted push: %s\n%s", err, out))
c.Assert(out, checker.Contains, "Signing and pushing trust metadata", check.Commentf("Missing expected output on trusted push with expired timestamp"))
})
}
示例3: TestPostContainersCreateWithWrongCpusetValues
func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C) {
testRequires(c, DaemonIsLinux)
c1 := struct {
Image string
CpusetCpus string
}{"busybox", "1-42,,"}
name := "wrong-cpuset-cpus"
status, body, err := sockRequest("POST", "/containers/create?name="+name, c1)
c.Assert(err, check.IsNil)
c.Assert(status, check.Equals, http.StatusInternalServerError)
expected := "Invalid value 1-42,, for cpuset cpus.\n"
c.Assert(string(body), check.Equals, expected, check.Commentf("Expected output to contain %q, got %q", expected, string(body)))
c2 := struct {
Image string
CpusetMems string
}{"busybox", "42-3,1--"}
name = "wrong-cpuset-mems"
status, body, err = sockRequest("POST", "/containers/create?name="+name, c2)
c.Assert(err, check.IsNil)
c.Assert(status, check.Equals, http.StatusInternalServerError)
expected = "Invalid value 42-3,1-- for cpuset mems.\n"
c.Assert(string(body), check.Equals, expected, check.Commentf("Expected output to contain %q, got %q", expected, string(body)))
}
示例4: TestEventsLimit
func (s *DockerSuite) TestEventsLimit(c *check.C) {
// Limit to 8 goroutines creating containers in order to prevent timeouts
// creating so many containers simultaneously on Windows
sem := make(chan bool, 8)
numContainers := 17
errChan := make(chan error, numContainers)
args := []string{"run", "--rm", "busybox", "true"}
for i := 0; i < numContainers; i++ {
sem <- true
go func() {
defer func() { <-sem }()
out, err := exec.Command(dockerBinary, args...).CombinedOutput()
if err != nil {
err = fmt.Errorf("%v: %s", err, string(out))
}
errChan <- err
}()
}
// Wait for all goroutines to finish
for i := 0; i < cap(sem); i++ {
sem <- true
}
close(errChan)
for err := range errChan {
c.Assert(err, checker.IsNil, check.Commentf("%q failed with error", strings.Join(args, " ")))
}
out, _ := dockerCmd(c, "events", "--since=0", "--until", daemonUnixTime(c))
events := strings.Split(out, "\n")
nEvents := len(events) - 1
c.Assert(nEvents, checker.Equals, 64, check.Commentf("events should be limited to 64, but received %d", nEvents))
}
示例5: TestEventsAttach
func (s *DockerSuite) TestEventsAttach(c *check.C) {
// TODO Windows CI: Figure out why this test fails intermittently (TP5).
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-di", "busybox", "cat")
cID := strings.TrimSpace(out)
c.Assert(waitRun(cID), checker.IsNil)
cmd := exec.Command(dockerBinary, "attach", cID)
stdin, err := cmd.StdinPipe()
c.Assert(err, checker.IsNil)
defer stdin.Close()
stdout, err := cmd.StdoutPipe()
c.Assert(err, checker.IsNil)
defer stdout.Close()
c.Assert(cmd.Start(), checker.IsNil)
defer cmd.Process.Kill()
// Make sure we're done attaching by writing/reading some stuff
_, err = stdin.Write([]byte("hello\n"))
c.Assert(err, checker.IsNil)
out, err = bufio.NewReader(stdout).ReadString('\n')
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(out), checker.Equals, "hello", check.Commentf("expected 'hello'"))
c.Assert(stdin.Close(), checker.IsNil)
dockerCmd(c, "kill", cID)
c.Assert(waitExited(cID, 5*time.Second), checker.IsNil)
until := daemonUnixTime(c)
out, _ = dockerCmd(c, "events", "-f", "container="+cID, "--until="+until)
c.Assert(out, checker.Contains, "attach", check.Commentf("Missing 'attach' log event"))
}
示例6: TestEventsFilterImageLabels
func (s *DockerSuite) TestEventsFilterImageLabels(c *check.C) {
since := daemonUnixTime(c)
name := "labelfiltertest"
label := "io.docker.testing=image"
// Build a test image.
_, err := buildImage(name, fmt.Sprintf(`
FROM busybox:latest
LABEL %s`, label), true)
c.Assert(err, checker.IsNil, check.Commentf("Couldn't create image"))
dockerCmd(c, "tag", name, "labelfiltertest:tag1")
dockerCmd(c, "tag", name, "labelfiltertest:tag2")
dockerCmd(c, "tag", "busybox:latest", "labelfiltertest:tag3")
out, _ := dockerCmd(
c,
"events",
"--since", since,
"--until", daemonUnixTime(c),
"--filter", fmt.Sprintf("label=%s", label),
"--filter", "type=image")
events := strings.Split(strings.TrimSpace(out), "\n")
// 2 events from the "docker tag" command, another one is from "docker build"
c.Assert(events, checker.HasLen, 3, check.Commentf("Events == %s", events))
for _, e := range events {
c.Assert(e, checker.Contains, "labelfiltertest")
}
}
示例7: TestEventsPluginOps
func (s *DockerSuite) TestEventsPluginOps(c *check.C) {
testRequires(c, DaemonIsLinux, ExperimentalDaemon)
pluginName := "tiborvass/no-remove:latest"
since := daemonUnixTime(c)
dockerCmd(c, "plugin", "install", pluginName, "--grant-all-permissions")
dockerCmd(c, "plugin", "disable", pluginName)
dockerCmd(c, "plugin", "remove", pluginName)
out, _ := dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c))
events := strings.Split(out, "\n")
events = events[:len(events)-1]
nEvents := len(events)
c.Assert(nEvents, checker.GreaterOrEqualThan, 4)
pluginEvents := eventActionsByIDAndType(c, events, pluginName, "plugin")
c.Assert(pluginEvents, checker.HasLen, 4, check.Commentf("events: %v", events))
c.Assert(pluginEvents[0], checker.Equals, "pull", check.Commentf(out))
c.Assert(pluginEvents[1], checker.Equals, "enable", check.Commentf(out))
c.Assert(pluginEvents[2], checker.Equals, "disable", check.Commentf(out))
c.Assert(pluginEvents[3], checker.Equals, "remove", check.Commentf(out))
}
示例8: TestExecWithPrivileged
func (s *DockerSuite) TestExecWithPrivileged(c *check.C) {
// Not applicable on Windows
testRequires(c, DaemonIsLinux, NotUserNamespace)
// Start main loop which attempts mknod repeatedly
dockerCmd(c, "run", "-d", "--name", "parent", "--cap-drop=ALL", "busybox", "sh", "-c", `while (true); do if [ -e /exec_priv ]; then cat /exec_priv && mknod /tmp/sda b 8 0 && echo "Success"; else echo "Privileged exec has not run yet"; fi; usleep 10000; done`)
// Check exec mknod doesn't work
cmd := exec.Command(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdb b 8 16")
out, _, err := runCommandWithOutput(cmd)
c.Assert(err, checker.NotNil, check.Commentf("exec mknod in --cap-drop=ALL container without --privileged should fail"))
c.Assert(out, checker.Contains, "Operation not permitted", check.Commentf("exec mknod in --cap-drop=ALL container without --privileged should fail"))
// Check exec mknod does work with --privileged
cmd = exec.Command(dockerBinary, "exec", "--privileged", "parent", "sh", "-c", `echo "Running exec --privileged" > /exec_priv && mknod /tmp/sdb b 8 16 && usleep 50000 && echo "Finished exec --privileged" > /exec_priv && echo ok`)
out, _, err = runCommandWithOutput(cmd)
c.Assert(err, checker.IsNil)
actual := strings.TrimSpace(out)
c.Assert(actual, checker.Equals, "ok", check.Commentf("exec mknod in --cap-drop=ALL container with --privileged failed, output: %q", out))
// Check subsequent unprivileged exec cannot mknod
cmd = exec.Command(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sdc b 8 32")
out, _, err = runCommandWithOutput(cmd)
c.Assert(err, checker.NotNil, check.Commentf("repeating exec mknod in --cap-drop=ALL container after --privileged without --privileged should fail"))
c.Assert(out, checker.Contains, "Operation not permitted", check.Commentf("repeating exec mknod in --cap-drop=ALL container after --privileged without --privileged should fail"))
// Confirm at no point was mknod allowed
logCmd := exec.Command(dockerBinary, "logs", "parent")
out, _, err = runCommandWithOutput(logCmd)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Not(checker.Contains), "Success")
}
示例9: TestEventsAttach
func (s *DockerSuite) TestEventsAttach(c *check.C) {
testRequires(c, DaemonIsLinux)
since := daemonTime(c).Unix()
out, _ := dockerCmd(c, "run", "-di", "busybox", "/bin/cat")
cID := strings.TrimSpace(out)
cmd := exec.Command(dockerBinary, "attach", cID)
stdin, err := cmd.StdinPipe()
c.Assert(err, checker.IsNil)
defer stdin.Close()
stdout, err := cmd.StdoutPipe()
c.Assert(err, checker.IsNil)
defer stdout.Close()
c.Assert(cmd.Start(), checker.IsNil)
defer cmd.Process.Kill()
// Make sure we're done attaching by writing/reading some stuff
_, err = stdin.Write([]byte("hello\n"))
c.Assert(err, checker.IsNil)
out, err = bufio.NewReader(stdout).ReadString('\n')
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(out), checker.Equals, "hello", check.Commentf("expected 'hello'"))
c.Assert(stdin.Close(), checker.IsNil)
dockerCmd(c, "stop", cID)
out, _ = dockerCmd(c, "events", "--since=0", "-f", "container="+cID, "--until="+strconv.Itoa(int(since)))
c.Assert(out, checker.Contains, " attach\n", check.Commentf("Missing 'attach' log event"))
}
示例10: TestEventsTimestampFormats
func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
testRequires(c, DaemonIsLinux)
image := "busybox"
// Start stopwatch, generate an event
time.Sleep(1 * time.Second) // so that we don't grab events from previous test occured in the same second
start := daemonTime(c)
dockerCmd(c, "tag", image, "timestamptest:1")
dockerCmd(c, "rmi", "timestamptest:1")
time.Sleep(1 * time.Second) // so that until > since
end := daemonTime(c)
// List of available time formats to --since
unixTs := func(t time.Time) string { return fmt.Sprintf("%v", t.Unix()) }
rfc3339 := func(t time.Time) string { return t.Format(time.RFC3339) }
duration := func(t time.Time) string { return time.Now().Sub(t).String() }
// --since=$start must contain only the 'untag' event
for _, f := range []func(time.Time) string{unixTs, rfc3339, duration} {
since, until := f(start), f(end)
out, _ := dockerCmd(c, "events", "--since="+since, "--until="+until)
events := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(events, checker.HasLen, 2, check.Commentf("unexpected events, was expecting only 2 events tag/untag (since=%s, until=%s) out=%s", since, until, out))
c.Assert(out, checker.Contains, "untag", check.Commentf("expected 'untag' event not found (since=%s, until=%s)", since, until))
}
}
示例11: TestContainerApiTop
func (s *DockerSuite) TestContainerApiTop(c *check.C) {
// Problematic on Windows as Windows does not support top
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "top")
id := strings.TrimSpace(string(out))
c.Assert(waitRun(id), checker.IsNil)
type topResp struct {
Titles []string
Processes [][]string
}
var top topResp
status, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK)
c.Assert(json.Unmarshal(b, &top), checker.IsNil)
c.Assert(top.Titles, checker.HasLen, 11, check.Commentf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles))
if top.Titles[0] != "USER" || top.Titles[10] != "COMMAND" {
c.Fatalf("expected `USER` at `Titles[0]` and `COMMAND` at Titles[10]: %v", top.Titles)
}
c.Assert(top.Processes, checker.HasLen, 2, check.Commentf("expected 2 processes, found %d: %v", len(top.Processes), top.Processes))
c.Assert(top.Processes[0][10], checker.Equals, "/bin/sh -c top")
c.Assert(top.Processes[1][10], checker.Equals, "top")
}
示例12: TestContainerApiPause
func (s *DockerSuite) TestContainerApiPause(c *check.C) {
// Problematic on Windows as Windows does not support pause
testRequires(c, DaemonIsLinux)
defer unpauseAllContainers()
out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "30")
ContainerID := strings.TrimSpace(out)
status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusNoContent)
pausedContainers, err := getSliceOfPausedContainers()
c.Assert(err, checker.IsNil, check.Commentf("error thrown while checking if containers were paused"))
if len(pausedContainers) != 1 || stringid.TruncateID(ContainerID) != pausedContainers[0] {
c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
}
status, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusNoContent)
pausedContainers, err = getSliceOfPausedContainers()
c.Assert(err, checker.IsNil, check.Commentf("error thrown while checking if containers were paused"))
c.Assert(pausedContainers, checker.IsNil, check.Commentf("There should be no paused container."))
}
示例13: TestContainerApiGetChanges
func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) {
// Not supported on Windows as Windows does not support docker diff (/containers/name/changes)
testRequires(c, DaemonIsLinux)
name := "changescontainer"
dockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd")
status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusOK)
changes := []struct {
Kind int
Path string
}{}
c.Assert(json.Unmarshal(body, &changes), checker.IsNil, check.Commentf("unable to unmarshal response body"))
// Check the changelog for removal of /etc/passwd
success := false
for _, elem := range changes {
if elem.Path == "/etc/passwd" && elem.Kind == 2 {
success = true
}
}
c.Assert(success, checker.True, check.Commentf("/etc/passwd has been removed but is not present in the diff"))
}
示例14: TestPsListContainersFilterIsTask
func (s *DockerSwarmSuite) TestPsListContainersFilterIsTask(c *check.C) {
d := s.AddDaemon(c, true, true)
// Create a bare container
out, err := d.Cmd("run", "-d", "--name=bare-container", "busybox", "top")
c.Assert(err, checker.IsNil)
bareID := strings.TrimSpace(out)[:12]
// Create a service
name := "busybox-top"
out, err = d.Cmd("service", "create", "--name", name, "busybox", "top")
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(out), checker.Not(checker.Equals), "")
// make sure task has been deployed.
waitAndAssert(c, defaultReconciliationTimeout, d.checkServiceRunningTasks(c, name), checker.Equals, 1)
// Filter non-tasks
out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=false")
c.Assert(err, checker.IsNil)
psOut := strings.TrimSpace(out)
c.Assert(psOut, checker.Equals, bareID, check.Commentf("Expected id %s, got %s for is-task label, output %q", bareID, psOut, out))
// Filter tasks
out, err = d.Cmd("ps", "-a", "-q", "--filter=is-task=true")
c.Assert(err, checker.IsNil)
lines := strings.Split(strings.Trim(out, "\n "), "\n")
c.Assert(lines, checker.HasLen, 1)
c.Assert(lines[0], checker.Not(checker.Equals), bareID, check.Commentf("Expected not %s, but got it for is-task label, output %q", bareID, out))
}
示例15: TestPullAllTagsFromCentralRegistry
// TestPullAllTagsFromCentralRegistry pulls using `all-tags` for a given image and verifies that it
// results in more images than a naked pull.
func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *check.C) {
testRequires(c, DaemonIsLinux)
s.Cmd(c, "pull", "busybox")
outImageCmd := s.Cmd(c, "images", "busybox")
splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n")
c.Assert(splitOutImageCmd, checker.HasLen, 2, check.Commentf("expected a single entry in images\n%v", outImageCmd))
s.Cmd(c, "pull", "--all-tags=true", "busybox")
outImageAllTagCmd := s.Cmd(c, "images", "busybox")
if linesCount := strings.Count(outImageAllTagCmd, "\n"); linesCount <= 2 {
c.Fatalf("pulling all tags should provide more images, got %d", linesCount-1)
}
// Verify that the line for 'busybox:latest' is left unchanged.
var latestLine string
for _, line := range strings.Split(outImageAllTagCmd, "\n") {
if strings.HasPrefix(line, "busybox") && strings.Contains(line, "latest") {
latestLine = line
break
}
}
c.Assert(latestLine, checker.Not(checker.Equals), "", check.Commentf("no entry for busybox:latest found after pulling all tags"))
splitLatest := strings.Fields(latestLine)
splitCurrent := strings.Fields(splitOutImageCmd[1])
c.Assert(splitLatest, checker.DeepEquals, splitCurrent, check.Commentf("busybox:latest was changed after pulling all tags"))
}