github.com/justincormack/cli@v0.0.0-20201215022714-831ebeae9675/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"
     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  	checkpoints := []types.Checkpoint{
    42  		{Name: "checkpoint-1"},
    43  		{Name: "checkpoint-2"},
    44  		{Name: "checkpoint-3"},
    45  	}
    46  	for _, testcase := range cases {
    47  		out := bytes.NewBufferString("")
    48  		testcase.context.Output = out
    49  		err := FormatWrite(testcase.context, checkpoints)
    50  		assert.NilError(t, err)
    51  		assert.Equal(t, out.String(), testcase.expected)
    52  	}
    53  }