Merge pull request #511 from dnephin/fix-end-of-line-whitespace-tests

Use golden files for tests that expect end-of-line whitespace
This commit is contained in:
Victor Vieux 2017-09-08 11:37:28 -07:00 committed by GitHub
commit d3d9b38d55
13 changed files with 67 additions and 62 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -230,10 +231,7 @@ size: 0B
// Special headers for customized table format // Special headers for customized table format
{ {
Context{Format: NewContainerFormat(`table {{truncate .ID 5}}\t{{json .Image}} {{.RunningFor}}/{{title .Status}}/{{pad .Ports 2 2}}.{{upper .Names}} {{lower .Status}}`, false, true)}, Context{Format: NewContainerFormat(`table {{truncate .ID 5}}\t{{json .Image}} {{.RunningFor}}/{{title .Status}}/{{pad .Ports 2 2}}.{{upper .Names}} {{lower .Status}}`, false, true)},
`CONTAINER ID IMAGE CREATED/STATUS/ PORTS .NAMES STATUS string(golden.Get(t, "container-context-write-special-headers.golden")),
conta "ubuntu" 24 hours ago//.FOOBAR_BAZ
conta "ubuntu" 24 hours ago//.FOOBAR_BAR
`,
}, },
} }

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -83,12 +84,7 @@ Build Cache 0B
Format: NewDiskUsageFormat("table {{.Type}}\t{{.Active}}"), Format: NewDiskUsageFormat("table {{.Type}}\t{{.Active}}"),
}, },
}, },
`TYPE ACTIVE string(golden.Get(t, "disk-usage-context-write-custom.golden")),
Images 0
Containers 0
Local Volumes 0
Build Cache
`,
}, },
// Raw Format // Raw Format
{ {
@ -97,31 +93,7 @@ Build Cache
Format: NewDiskUsageFormat("raw"), Format: NewDiskUsageFormat("raw"),
}, },
}, },
`type: Images string(golden.Get(t, "disk-usage-raw-format.golden")),
total: 0
active: 0
size: 0B
reclaimable: 0B
type: Containers
total: 0
active: 0
size: 0B
reclaimable: 0B
type: Local Volumes
total: 0
active: 0
size: 0B
reclaimable: 0B
type: Build Cache
total:
active:
size: 0B
reclaimable: 0B
`,
}, },
} }

View File

@ -8,6 +8,7 @@ import (
registrytypes "github.com/docker/docker/api/types/registry" registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/stringutils" "github.com/docker/docker/pkg/stringutils"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -120,10 +121,7 @@ func TestSearchContextWrite(t *testing.T) {
// Table format // Table format
{ {
Context{Format: NewSearchFormat("table")}, Context{Format: NewSearchFormat("table")},
`NAME DESCRIPTION STARS OFFICIAL AUTOMATED string(golden.Get(t, "search-context-write-table.golden")),
result1 Official build 5000 [OK]
result2 Not official 5 [OK]
`,
}, },
{ {
Context{Format: NewSearchFormat("table {{.Name}}")}, Context{Format: NewSearchFormat("table {{.Name}}")},
@ -210,9 +208,7 @@ func TestSearchContextWriteStars(t *testing.T) {
// Table format // Table format
{ {
Context{Format: NewSearchFormat("table")}, Context{Format: NewSearchFormat("table")},
`NAME DESCRIPTION STARS OFFICIAL AUTOMATED string(golden.Get(t, "search-context-write-stars-table.golden")),
result1 Official build 5000 [OK]
`,
}, },
{ {
Context{Format: NewSearchFormat("table {{.Name}}")}, Context{Format: NewSearchFormat("table {{.Name}}")},

View File

@ -8,6 +8,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -59,21 +60,7 @@ bar
// Raw Format // Raw Format
{ {
Context{Format: NewServiceListFormat("raw", false)}, Context{Format: NewServiceListFormat("raw", false)},
`id: id_baz string(golden.Get(t, "service-context-write-raw.golden")),
name: baz
mode: global
replicas: 2/4
image:
ports: *:80->8080/tcp
id: id_bar
name: bar
mode: replicated
replicas: 2/4
image:
ports: *:80->8080/tcp
`,
}, },
{ {
Context{Format: NewServiceListFormat("raw", true)}, Context{Format: NewServiceListFormat("raw", true)},

View File

@ -7,6 +7,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -33,10 +34,7 @@ taskID2
}, },
{ {
Context{Format: NewTaskFormat("table {{.Name}}\t{{.Node}}\t{{.Ports}}", false)}, Context{Format: NewTaskFormat("table {{.Name}}\t{{.Node}}\t{{.Ports}}", false)},
`NAME NODE PORTS string(golden.Get(t, "task-context-write-table-custom.golden")),
foobar_baz foo1
foobar_bar foo2
`,
}, },
{ {
Context{Format: NewTaskFormat("table {{.Name}}", true)}, Context{Format: NewTaskFormat("table {{.Name}}", true)},

View File

@ -0,0 +1,3 @@
CONTAINER ID IMAGE CREATED/STATUS/ PORTS .NAMES STATUS
conta "ubuntu" 24 hours ago//.FOOBAR_BAZ
conta "ubuntu" 24 hours ago//.FOOBAR_BAR

View File

@ -0,0 +1,5 @@
TYPE ACTIVE
Images 0
Containers 0
Local Volumes 0
Build Cache

View File

@ -0,0 +1,24 @@
type: Images
total: 0
active: 0
size: 0B
reclaimable: 0B
type: Containers
total: 0
active: 0
size: 0B
reclaimable: 0B
type: Local Volumes
total: 0
active: 0
size: 0B
reclaimable: 0B
type: Build Cache
total:
active:
size: 0B
reclaimable: 0B

View File

@ -0,0 +1,2 @@
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
result1 Official build 5000 [OK]

View File

@ -0,0 +1,3 @@
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
result1 Official build 5000 [OK]
result2 Not official 5 [OK]

View File

@ -0,0 +1,14 @@
id: id_baz
name: baz
mode: global
replicas: 2/4
image:
ports: *:80->8080/tcp
id: id_bar
name: bar
mode: replicated
replicas: 2/4
image:
ports: *:80->8080/tcp

View File

@ -0,0 +1,3 @@
NAME NODE PORTS
foobar_baz foo1
foobar_bar foo2

View File

@ -11,7 +11,7 @@ for pkg in "$@"; do
-coverprofile=profile.out \ -coverprofile=profile.out \
-covermode=atomic \ -covermode=atomic \
"${pkg}" "${pkg}"
if test -f profile.out; then if test -f profile.out; then
cat profile.out >> coverage.txt cat profile.out >> coverage.txt
rm profile.out rm profile.out