summaryrefslogtreecommitdiff
path: root/cmd/podman/report/format_test.go
blob: 7dd62e899e7b94807cf9d4837e05228bdc8be718 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package report

import (
	"strings"
	"testing"
)

func TestNormalizeFormat(t *testing.T) {
	cases := []struct {
		format   string
		expected string
	}{
		{"table {{.ID}}", "{{.ID}}\n"},
		{"table {{.ID}} {{.C}}", "{{.ID}}\t{{.C}}\n"},
		{"{{.ID}}", "{{.ID}}\n"},
		{"{{.ID}}\n", "{{.ID}}\n"},
		{"{{.ID}} {{.C}}", "{{.ID}} {{.C}}\n"},
		{"\t{{.ID}}", "\t{{.ID}}\n"},
		{`\t` + "{{.ID}}", "\t{{.ID}}\n"},
		{"table {{.ID}}\t{{.C}}", "{{.ID}}\t{{.C}}\n"},
		{"{{.ID}} table {{.C}}", "{{.ID}} table {{.C}}\n"},
	}
	for _, tc := range cases {
		tc := tc

		label := strings.ReplaceAll(tc.format, " ", "<sp>")
		t.Run("NormalizeFormat/"+label, func(t *testing.T) {
			t.Parallel()
			actual := NormalizeFormat(tc.format)
			if actual != tc.expected {
				t.Errorf("Expected %q, actual %q", tc.expected, actual)
			}
		})
	}
}