本文整理汇总了Golang中github.com/docker/docker/daemon/events/testutils.ScanMap函数的典型用法代码示例。如果您正苦于以下问题:Golang ScanMap函数的具体用法?Golang ScanMap怎么用?Golang ScanMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ScanMap函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: parseEvents
func parseEvents(c *check.C, out, match string) {
events := strings.Split(strings.TrimSpace(out), "\n")
for _, event := range events {
matches := eventstestutils.ScanMap(event)
matched, err := regexp.MatchString(match, matches["action"])
c.Assert(err, checker.IsNil)
c.Assert(matched, checker.True, check.Commentf("Matcher: %s did not match %s", match, matches["action"]))
}
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:9,代码来源:events_utils.go
示例2: eventActionsByIDAndType
// eventActionsByIDAndType returns the actions for a given id and type.
// It fails if the text is not in the event format.
func eventActionsByIDAndType(c *check.C, events []string, id, eventType string) []string {
var filtered []string
for _, event := range events {
matches := eventstestutils.ScanMap(event)
c.Assert(matches, checker.Not(checker.IsNil))
if matchIDAndEventType(matches, id, eventType) {
filtered = append(filtered, matches["action"])
}
}
return filtered
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:13,代码来源:events_utils.go
示例3: TestEventsImageLoad
func (s *DockerSuite) TestEventsImageLoad(c *check.C) {
testRequires(c, DaemonIsLinux)
myImageName := "footest:v1"
dockerCmd(c, "tag", "busybox", myImageName)
since := daemonUnixTime(c)
out, _ := dockerCmd(c, "images", "-q", "--no-trunc", myImageName)
longImageID := strings.TrimSpace(out)
c.Assert(longImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty"))
dockerCmd(c, "save", "-o", "saveimg.tar", myImageName)
dockerCmd(c, "rmi", myImageName)
out, _ = dockerCmd(c, "images", "-q", myImageName)
noImageID := strings.TrimSpace(out)
c.Assert(noImageID, checker.Equals, "", check.Commentf("Should not have any image"))
dockerCmd(c, "load", "-i", "saveimg.tar")
result := icmd.RunCommand("rm", "-rf", "saveimg.tar")
c.Assert(result, icmd.Matches, icmd.Success)
out, _ = dockerCmd(c, "images", "-q", "--no-trunc", myImageName)
imageID := strings.TrimSpace(out)
c.Assert(imageID, checker.Equals, longImageID, check.Commentf("Should have same image id as before"))
out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=load")
events := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(events, checker.HasLen, 1)
matches := eventstestutils.ScanMap(events[0])
c.Assert(matches["id"], checker.Equals, imageID, check.Commentf("matches: %v\nout:\n%s\n", matches, out))
c.Assert(matches["action"], checker.Equals, "load", check.Commentf("matches: %v\nout:\n%s\n", matches, out))
out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=save")
events = strings.Split(strings.TrimSpace(out), "\n")
c.Assert(events, checker.HasLen, 1)
matches = eventstestutils.ScanMap(events[0])
c.Assert(matches["id"], checker.Equals, imageID, check.Commentf("matches: %v\nout:\n%s\n", matches, out))
c.Assert(matches["action"], checker.Equals, "save", check.Commentf("matches: %v\nout:\n%s\n", matches, out))
}
开发者ID:Mic92,项目名称:docker,代码行数:38,代码来源:docker_cli_events_test.go
示例4: matchEventLine
// matchEventLine matches a text with the event regular expression.
// It returns the matches and true if the regular expression matches with the given id and event type.
// It returns an empty map and false if there is no match.
func matchEventLine(id, eventType string, actions map[string]chan bool) eventMatcher {
return func(text string) (map[string]string, bool) {
matches := eventstestutils.ScanMap(text)
if len(matches) == 0 {
return matches, false
}
if matchIDAndEventType(matches, id, eventType) {
if _, ok := actions[matches["action"]]; ok {
return matches, true
}
}
return matches, false
}
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:18,代码来源:events_utils.go
示例5: TestEventsImageTag
func (s *DockerSuite) TestEventsImageTag(c *check.C) {
time.Sleep(1 * time.Second) // because API has seconds granularity
since := daemonUnixTime(c)
image := "testimageevents:tag"
dockerCmd(c, "tag", "busybox", image)
out, _ := dockerCmd(c, "events",
"--since", since, "--until", daemonUnixTime(c))
events := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(events, checker.HasLen, 1, check.Commentf("was expecting 1 event. out=%s", out))
event := strings.TrimSpace(events[0])
matches := eventstestutils.ScanMap(event)
c.Assert(matchEventID(matches, image), checker.True, check.Commentf("matches: %v\nout:\n%s", matches, out))
c.Assert(matches["action"], checker.Equals, "tag")
}
开发者ID:Mic92,项目名称:docker,代码行数:17,代码来源:docker_cli_events_test.go
示例6: TestEventsImagePull
func (s *DockerSuite) TestEventsImagePull(c *check.C) {
// TODO Windows: Enable this test once pull and reliable image names are available
testRequires(c, DaemonIsLinux)
since := daemonUnixTime(c)
testRequires(c, Network)
dockerCmd(c, "pull", "hello-world")
out, _ := dockerCmd(c, "events",
"--since", since, "--until", daemonUnixTime(c))
events := strings.Split(strings.TrimSpace(out), "\n")
event := strings.TrimSpace(events[len(events)-1])
matches := eventstestutils.ScanMap(event)
c.Assert(matches["id"], checker.Equals, "hello-world:latest")
c.Assert(matches["action"], checker.Equals, "pull")
}
开发者ID:Mic92,项目名称:docker,代码行数:18,代码来源:docker_cli_events_test.go
示例7: TestEventsContainerEventsAttrSort
func (s *DockerSuite) TestEventsContainerEventsAttrSort(c *check.C) {
since := daemonUnixTime(c)
dockerCmd(c, "run", "--rm", "--name", "container-events-test", "busybox", "true")
out, _ := dockerCmd(c, "events", "--filter", "container=container-events-test", "--since", since, "--until", daemonUnixTime(c))
events := strings.Split(out, "\n")
nEvents := len(events)
c.Assert(nEvents, checker.GreaterOrEqualThan, 3) //Missing expected event
matchedEvents := 0
for _, event := range events {
matches := eventstestutils.ScanMap(event)
if matches["eventType"] == "container" && matches["action"] == "create" {
matchedEvents++
c.Assert(out, checker.Contains, "(image=busybox, name=container-events-test)", check.Commentf("Event attributes not sorted"))
} else if matches["eventType"] == "container" && matches["action"] == "start" {
matchedEvents++
c.Assert(out, checker.Contains, "(image=busybox, name=container-events-test)", check.Commentf("Event attributes not sorted"))
}
}
c.Assert(matchedEvents, checker.Equals, 2, check.Commentf("missing events for container container-events-test:\n%s", out))
}
开发者ID:Mic92,项目名称:docker,代码行数:22,代码来源:docker_cli_events_test.go
示例8: TestEventsImageImport
func (s *DockerSuite) TestEventsImageImport(c *check.C) {
// TODO Windows CI. This should be portable once export/import are
// more reliable (@swernli)
testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
cleanedContainerID := strings.TrimSpace(out)
since := daemonUnixTime(c)
out, _, err := runCommandPipelineWithOutput(
exec.Command(dockerBinary, "export", cleanedContainerID),
exec.Command(dockerBinary, "import", "-"),
)
c.Assert(err, checker.IsNil, check.Commentf("import failed with output: %q", out))
imageRef := strings.TrimSpace(out)
out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=import")
events := strings.Split(strings.TrimSpace(out), "\n")
c.Assert(events, checker.HasLen, 1)
matches := eventstestutils.ScanMap(events[0])
c.Assert(matches["id"], checker.Equals, imageRef, check.Commentf("matches: %v\nout:\n%s\n", matches, out))
c.Assert(matches["action"], checker.Equals, "import", check.Commentf("matches: %v\nout:\n%s\n", matches, out))
}
开发者ID:Mic92,项目名称:docker,代码行数:23,代码来源:docker_cli_events_test.go
示例9: TestEventsFilterContainer
func (s *DockerSuite) TestEventsFilterContainer(c *check.C) {
since := daemonUnixTime(c)
nameID := make(map[string]string)
for _, name := range []string{"container_1", "container_2"} {
dockerCmd(c, "run", "--name", name, "busybox", "true")
id := inspectField(c, name, "Id")
nameID[name] = id
}
until := daemonUnixTime(c)
checkEvents := func(id string, events []string) error {
if len(events) != 4 { // create, attach, start, die
return fmt.Errorf("expected 4 events, got %v", events)
}
for _, event := range events {
matches := eventstestutils.ScanMap(event)
if !matchEventID(matches, id) {
return fmt.Errorf("expected event for container id %s: %s - parsed container id: %s", id, event, matches["id"])
}
}
return nil
}
for name, ID := range nameID {
// filter by names
out, _ := dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+name)
events := strings.Split(strings.TrimSuffix(out, "\n"), "\n")
c.Assert(checkEvents(ID, events), checker.IsNil)
// filter by ID's
out, _ = dockerCmd(c, "events", "--since", since, "--until", until, "--filter", "container="+ID)
events = strings.Split(strings.TrimSuffix(out, "\n"), "\n")
c.Assert(checkEvents(ID, events), checker.IsNil)
}
}
开发者ID:Mic92,项目名称:docker,代码行数:37,代码来源:docker_cli_events_test.go
示例10: parseEventAction
// parseEventAction parses an event text and returns the action.
// It fails if the text is not in the event format.
func parseEventAction(c *check.C, text string) string {
matches := eventstestutils.ScanMap(text)
return matches["action"]
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:6,代码来源:events_utils.go
注:本文中的github.com/docker/docker/daemon/events/testutils.ScanMap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论