checkpoint_test.go 996 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package formatter
  2. import (
  3. "bytes"
  4. "testing"
  5. "github.com/docker/docker/api/types"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestCheckpointContextFormatWrite(t *testing.T) {
  9. cases := []struct {
  10. context Context
  11. expected string
  12. }{
  13. {
  14. Context{Format: NewCheckpointFormat(defaultCheckpointFormat)},
  15. `CHECKPOINT NAME
  16. checkpoint-1
  17. checkpoint-2
  18. checkpoint-3
  19. `,
  20. },
  21. {
  22. Context{Format: NewCheckpointFormat("{{.Name}}")},
  23. `checkpoint-1
  24. checkpoint-2
  25. checkpoint-3
  26. `,
  27. },
  28. {
  29. Context{Format: NewCheckpointFormat("{{.Name}}:")},
  30. `checkpoint-1:
  31. checkpoint-2:
  32. checkpoint-3:
  33. `,
  34. },
  35. }
  36. checkpoints := []types.Checkpoint{
  37. {"checkpoint-1"},
  38. {"checkpoint-2"},
  39. {"checkpoint-3"},
  40. }
  41. for _, testcase := range cases {
  42. out := bytes.NewBufferString("")
  43. testcase.context.Output = out
  44. err := CheckpointWrite(testcase.context, checkpoints)
  45. if err != nil {
  46. assert.Error(t, err, testcase.expected)
  47. } else {
  48. assert.Equal(t, out.String(), testcase.expected)
  49. }
  50. }
  51. }