github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/checkpoint/formatter_test.go (about) 1 package checkpoint 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/docker/cli/cli/command/formatter" 8 "github.com/docker/docker/api/types/checkpoint" 9 "gotest.tools/v3/assert" 10 ) 11 12 func TestCheckpointContextFormatWrite(t *testing.T) { 13 cases := []struct { 14 context formatter.Context 15 expected string 16 }{ 17 { 18 formatter.Context{Format: NewFormat(defaultCheckpointFormat)}, 19 `CHECKPOINT NAME 20 checkpoint-1 21 checkpoint-2 22 checkpoint-3 23 `, 24 }, 25 { 26 formatter.Context{Format: NewFormat("{{.Name}}")}, 27 `checkpoint-1 28 checkpoint-2 29 checkpoint-3 30 `, 31 }, 32 { 33 formatter.Context{Format: NewFormat("{{.Name}}:")}, 34 `checkpoint-1: 35 checkpoint-2: 36 checkpoint-3: 37 `, 38 }, 39 } 40 41 for _, testcase := range cases { 42 out := bytes.NewBufferString("") 43 testcase.context.Output = out 44 err := FormatWrite(testcase.context, []checkpoint.Summary{ 45 {Name: "checkpoint-1"}, 46 {Name: "checkpoint-2"}, 47 {Name: "checkpoint-3"}, 48 }) 49 assert.NilError(t, err) 50 assert.Equal(t, out.String(), testcase.expected) 51 } 52 }