DockerCLI/cli/command/formatter/disk_usage_test.go

121 lines
2.9 KiB
Go
Raw Normal View History

package formatter
import (
"bytes"
"testing"
"gotest.tools/v3/assert"
"gotest.tools/v3/golden"
)
func TestDiskUsageContextFormatWrite(t *testing.T) {
cases := []struct {
context DiskUsageContext
expected string
}{
// Check default output format (verbose and non-verbose mode) for table headers
{
DiskUsageContext{
Context: Context{
Format: NewDiskUsageFormat("table", false),
},
Verbose: false,
},
formatter: reduce minimum width for columns in table-view The tabwriter was configured to have a min-width for columns of 20 positions. This seemed quite wide, and caused smaller columns to be printed with a large gap between. Before: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.00% 800KiB / 1.944GiB 0.04% 1.44kB / 0B 0B / 0B 1 403c101bad56 agitated_swartz 0.15% 34.31MiB / 1.944GiB 1.72% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1.012MiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 972KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 820KiB / 1.944GiB 0.04% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 4 hours ago Up 4 hours amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB After: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.14% 5.703MiB / 1.944GiB 0.29% 1.44kB / 0B 0B / 0B 10 403c101bad56 agitated_swartz 0.15% 56.97MiB / 1.944GiB 2.86% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1016KiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 956KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 980KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 12 minutes ago Up 12 minutes amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-28 17:00:21 -04:00
`TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 0 0 0B 0B
Containers 0 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
`,
},
{
DiskUsageContext{Verbose: true, Context: Context{Format: NewDiskUsageFormat("table", true)}},
`Images space usage:
formatter: reduce minimum width for columns in table-view The tabwriter was configured to have a min-width for columns of 20 positions. This seemed quite wide, and caused smaller columns to be printed with a large gap between. Before: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.00% 800KiB / 1.944GiB 0.04% 1.44kB / 0B 0B / 0B 1 403c101bad56 agitated_swartz 0.15% 34.31MiB / 1.944GiB 1.72% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1.012MiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 972KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 820KiB / 1.944GiB 0.04% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 4 hours ago Up 4 hours amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB After: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.14% 5.703MiB / 1.944GiB 0.29% 1.44kB / 0B 0B / 0B 10 403c101bad56 agitated_swartz 0.15% 56.97MiB / 1.944GiB 2.86% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1016KiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 956KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 980KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 12 minutes ago Up 12 minutes amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-28 17:00:21 -04:00
REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS
Containers space usage:
formatter: reduce minimum width for columns in table-view The tabwriter was configured to have a min-width for columns of 20 positions. This seemed quite wide, and caused smaller columns to be printed with a large gap between. Before: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.00% 800KiB / 1.944GiB 0.04% 1.44kB / 0B 0B / 0B 1 403c101bad56 agitated_swartz 0.15% 34.31MiB / 1.944GiB 1.72% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1.012MiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 972KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 820KiB / 1.944GiB 0.04% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 4 hours ago Up 4 hours amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB After: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.14% 5.703MiB / 1.944GiB 0.29% 1.44kB / 0B 0B / 0B 10 403c101bad56 agitated_swartz 0.15% 56.97MiB / 1.944GiB 2.86% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1016KiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 956KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 980KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 12 minutes ago Up 12 minutes amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-28 17:00:21 -04:00
CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES
Local Volumes space usage:
formatter: reduce minimum width for columns in table-view The tabwriter was configured to have a min-width for columns of 20 positions. This seemed quite wide, and caused smaller columns to be printed with a large gap between. Before: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.00% 800KiB / 1.944GiB 0.04% 1.44kB / 0B 0B / 0B 1 403c101bad56 agitated_swartz 0.15% 34.31MiB / 1.944GiB 1.72% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1.012MiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 972KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 820KiB / 1.944GiB 0.04% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 4 hours ago Up 4 hours amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB After: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.14% 5.703MiB / 1.944GiB 0.29% 1.44kB / 0B 0B / 0B 10 403c101bad56 agitated_swartz 0.15% 56.97MiB / 1.944GiB 2.86% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1016KiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 956KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 980KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 12 minutes ago Up 12 minutes amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-28 17:00:21 -04:00
VOLUME NAME LINKS SIZE
Build cache usage: 0B
formatter: reduce minimum width for columns in table-view The tabwriter was configured to have a min-width for columns of 20 positions. This seemed quite wide, and caused smaller columns to be printed with a large gap between. Before: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.00% 800KiB / 1.944GiB 0.04% 1.44kB / 0B 0B / 0B 1 403c101bad56 agitated_swartz 0.15% 34.31MiB / 1.944GiB 1.72% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1.012MiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 972KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 820KiB / 1.944GiB 0.04% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 4 hours ago Up 4 hours amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB After: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.14% 5.703MiB / 1.944GiB 0.29% 1.44kB / 0B 0B / 0B 10 403c101bad56 agitated_swartz 0.15% 56.97MiB / 1.944GiB 2.86% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1016KiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 956KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 980KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 12 minutes ago Up 12 minutes amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-28 17:00:21 -04:00
CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
`,
},
{
DiskUsageContext{Verbose: true, Context: Context{Format: NewDiskUsageFormat("raw", true)}},
``,
},
{
DiskUsageContext{Verbose: true, Context: Context{Format: NewDiskUsageFormat("{{json .}}", true)}},
`{"Images":[],"Containers":[],"Volumes":[],"BuildCache":[]}`,
},
// Errors
{
DiskUsageContext{
Context: Context{
Format: "{{InvalidFunction}}",
},
},
linting: fix incorrectly formatted errors (revive) cli/compose/interpolation/interpolation.go:102:4: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) "invalid interpolation format for %s: %#v. You may need to escape any $ with another $.", ^ cli/command/stack/loader/loader.go:30:30: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n", ^ cli/command/formatter/formatter.go:76:30: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return tmpl, errors.Errorf("Template parsing error: %v\n", err) ^ cli/command/formatter/formatter.go:97:24: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return errors.Errorf("Template parsing error: %v\n", err) ^ cli/command/image/build.go:257:25: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return errors.Errorf("error checking context: '%s'.", err) ^ cli/command/volume/create.go:35:27: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return errors.Errorf("Conflicting options: either specify --name or provide positional arg, not both\n") ^ cli/command/container/create.go:160:24: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return errors.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-27 15:13:03 -04:00
`template parsing error: template: :1: function "InvalidFunction" not defined`,
},
{
DiskUsageContext{
Context: Context{
Format: "{{nil}}",
},
},
linting: fix incorrectly formatted errors (revive) cli/compose/interpolation/interpolation.go:102:4: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) "invalid interpolation format for %s: %#v. You may need to escape any $ with another $.", ^ cli/command/stack/loader/loader.go:30:30: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n", ^ cli/command/formatter/formatter.go:76:30: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return tmpl, errors.Errorf("Template parsing error: %v\n", err) ^ cli/command/formatter/formatter.go:97:24: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return errors.Errorf("Template parsing error: %v\n", err) ^ cli/command/image/build.go:257:25: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return errors.Errorf("error checking context: '%s'.", err) ^ cli/command/volume/create.go:35:27: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return errors.Errorf("Conflicting options: either specify --name or provide positional arg, not both\n") ^ cli/command/container/create.go:160:24: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive) return errors.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-27 15:13:03 -04:00
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
},
// Table Format
{
DiskUsageContext{
Context: Context{
Format: NewDiskUsageFormat("table", false),
},
},
formatter: reduce minimum width for columns in table-view The tabwriter was configured to have a min-width for columns of 20 positions. This seemed quite wide, and caused smaller columns to be printed with a large gap between. Before: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.00% 800KiB / 1.944GiB 0.04% 1.44kB / 0B 0B / 0B 1 403c101bad56 agitated_swartz 0.15% 34.31MiB / 1.944GiB 1.72% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1.012MiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 972KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 820KiB / 1.944GiB 0.04% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 4 hours ago Up 4 hours amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB After: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.14% 5.703MiB / 1.944GiB 0.29% 1.44kB / 0B 0B / 0B 10 403c101bad56 agitated_swartz 0.15% 56.97MiB / 1.944GiB 2.86% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1016KiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 956KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 980KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 12 minutes ago Up 12 minutes amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-28 17:00:21 -04:00
`TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 0 0 0B 0B
Containers 0 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
`,
},
{
DiskUsageContext{
Context: Context{
Format: NewDiskUsageFormat("table {{.Type}}\t{{.Active}}", false),
},
},
string(golden.Get(t, "disk-usage-context-write-custom.golden")),
},
// Raw Format
{
DiskUsageContext{
Context: Context{
Format: NewDiskUsageFormat("raw", false),
},
},
string(golden.Get(t, "disk-usage-raw-format.golden")),
},
}
formatter: reduce minimum width for columns in table-view The tabwriter was configured to have a min-width for columns of 20 positions. This seemed quite wide, and caused smaller columns to be printed with a large gap between. Before: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.00% 800KiB / 1.944GiB 0.04% 1.44kB / 0B 0B / 0B 1 403c101bad56 agitated_swartz 0.15% 34.31MiB / 1.944GiB 1.72% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1.012MiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 972KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 820KiB / 1.944GiB 0.04% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 4 hours ago Up 4 hours amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB After: docker container stats CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 29184b3ae391 amazing_shirley 0.14% 5.703MiB / 1.944GiB 0.29% 1.44kB / 0B 0B / 0B 10 403c101bad56 agitated_swartz 0.15% 56.97MiB / 1.944GiB 2.86% 10.2MB / 206kB 0B / 0B 51 0dc4b7f6c6be container2 0.00% 1016KiB / 1.944GiB 0.05% 12.9kB / 0B 0B / 0B 5 2d99abcc6f62 container99 0.00% 956KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 9f9aa90173ac foo 0.00% 980KiB / 1.944GiB 0.05% 13kB / 0B 0B / 0B 5 docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 29184b3ae391 docker-cli-dev "ash" 12 minutes ago Up 12 minutes amazing_shirley 403c101bad56 docker-dev:master "hack/dind bash" 3 days ago Up 3 days agitated_swartz 0dc4b7f6c6be nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container2 2d99abcc6f62 nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp container99 9f9aa90173ac nginx:alpine "/docker-entrypoint.…" 4 days ago Up 4 days 80/tcp foo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-cli-dev latest 5f603caa04aa 4 hours ago 610MB docker-cli-native latest 9dd29f8d387b 4 hours ago 519MB docker-dev master 8132bf7a199e 3 days ago 2.02GB docker-dev improve-build-errors 69e208994b3f 11 days ago 2.01GB docker-dev refactor-idtools 69e208994b3f 11 days ago 2.01GB Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-08-28 17:00:21 -04:00
for _, tc := range cases {
tc := tc
t.Run(string(tc.context.Format), func(t *testing.T) {
var out bytes.Buffer
tc.context.Output = &out
if err := tc.context.Write(); err != nil {
assert.Error(t, err, tc.expected)
} else {
assert.Equal(t, out.String(), tc.expected)
}
})
}
}