mirror of https://github.com/docker/cli.git
Add unit test for `formatInfo`.
Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
01a591477c
commit
eb714f7c0e
|
@ -21,8 +21,10 @@ func base64Decode(val string) []byte {
|
|||
return decoded
|
||||
}
|
||||
|
||||
const sampleID = "EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX"
|
||||
|
||||
var sampleInfoNoSwarm = types.Info{
|
||||
ID: "EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX",
|
||||
ID: sampleID,
|
||||
Containers: 0,
|
||||
ContainersRunning: 0,
|
||||
ContainersPaused: 0,
|
||||
|
@ -263,3 +265,36 @@ func TestPrettyPrintInfo(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatInfo(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
doc string
|
||||
template string
|
||||
expectedError string
|
||||
expectedOut string
|
||||
}{
|
||||
{
|
||||
doc: "basic",
|
||||
template: "{{.ID}}",
|
||||
expectedOut: sampleID + "\n",
|
||||
},
|
||||
{
|
||||
doc: "syntax",
|
||||
template: "{{}",
|
||||
expectedError: `Status: Template parsing error: template: :1: unexpected "}" in command, Code: 64`,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.doc, func(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{})
|
||||
err := formatInfo(cli, sampleInfoNoSwarm, tc.template)
|
||||
if tc.expectedOut != "" {
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, cli.OutBuffer().String(), tc.expectedOut)
|
||||
} else if tc.expectedError != "" {
|
||||
assert.Error(t, err, tc.expectedError)
|
||||
} else {
|
||||
t.Fatal("test expected to neither pass nor fail")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue