github.com/Shopify/docker@v1.13.1/daemon/logger/loggerutils/log_tag_test.go (about) 1 package loggerutils 2 3 import ( 4 "testing" 5 6 "github.com/docker/docker/daemon/logger" 7 ) 8 9 func TestParseLogTagDefaultTag(t *testing.T) { 10 ctx := buildContext(map[string]string{}) 11 tag, e := ParseLogTag(ctx, "{{.ID}}") 12 assertTag(t, e, tag, ctx.ID()) 13 } 14 15 func TestParseLogTag(t *testing.T) { 16 ctx := buildContext(map[string]string{"tag": "{{.ImageName}}/{{.Name}}/{{.ID}}"}) 17 tag, e := ParseLogTag(ctx, "{{.ID}}") 18 assertTag(t, e, tag, "test-image/test-container/container-ab") 19 } 20 21 func TestParseLogTagEmptyTag(t *testing.T) { 22 ctx := buildContext(map[string]string{}) 23 tag, e := ParseLogTag(ctx, "{{.DaemonName}}/{{.ID}}") 24 assertTag(t, e, tag, "test-dockerd/container-ab") 25 } 26 27 // Helpers 28 29 func buildContext(cfg map[string]string) logger.Context { 30 return logger.Context{ 31 ContainerID: "container-abcdefghijklmnopqrstuvwxyz01234567890", 32 ContainerName: "/test-container", 33 ContainerImageID: "image-abcdefghijklmnopqrstuvwxyz01234567890", 34 ContainerImageName: "test-image", 35 Config: cfg, 36 DaemonName: "test-dockerd", 37 } 38 } 39 40 func assertTag(t *testing.T, e error, tag string, expected string) { 41 if e != nil { 42 t.Fatalf("Error generating tag: %q", e) 43 } 44 if tag != expected { 45 t.Fatalf("Wrong tag: %q, should be %q", tag, expected) 46 } 47 }