cli/command/container: TestContainerStatsContextWriteTrunc: use subtests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d65f0c9bbf
commit
18e911c958
@ -273,36 +273,37 @@ func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerStatsContextWriteTrunc(t *testing.T) {
|
func TestContainerStatsContextWriteTrunc(t *testing.T) {
|
||||||
var out bytes.Buffer
|
tests := []struct {
|
||||||
|
doc string
|
||||||
contexts := []struct {
|
|
||||||
context formatter.Context
|
context formatter.Context
|
||||||
trunc bool
|
trunc bool
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
formatter.Context{
|
doc: "non-truncated",
|
||||||
|
context: formatter.Context{
|
||||||
Format: "{{.ID}}",
|
Format: "{{.ID}}",
|
||||||
Output: &out,
|
|
||||||
},
|
},
|
||||||
false,
|
expected: "b95a83497c9161c9b444e3d70e1a9dfba0c1840d41720e146a95a08ebf938afc\n",
|
||||||
"b95a83497c9161c9b444e3d70e1a9dfba0c1840d41720e146a95a08ebf938afc\n",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{
|
doc: "truncated",
|
||||||
|
context: formatter.Context{
|
||||||
Format: "{{.ID}}",
|
Format: "{{.ID}}",
|
||||||
Output: &out,
|
|
||||||
},
|
},
|
||||||
true,
|
trunc: true,
|
||||||
"b95a83497c91\n",
|
expected: "b95a83497c91\n",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, context := range contexts {
|
for _, tc := range tests {
|
||||||
statsFormatWrite(context.context, []StatsEntry{{ID: "b95a83497c9161c9b444e3d70e1a9dfba0c1840d41720e146a95a08ebf938afc"}}, "linux", context.trunc)
|
t.Run(tc.doc, func(t *testing.T) {
|
||||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
var out bytes.Buffer
|
||||||
// Clean buffer
|
tc.context.Output = &out
|
||||||
out.Reset()
|
err := statsFormatWrite(tc.context, []StatsEntry{{ID: "b95a83497c9161c9b444e3d70e1a9dfba0c1840d41720e146a95a08ebf938afc"}}, "linux", tc.trunc)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Check(t, is.Equal(tc.expected, out.String()))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user