spiegel_podman/cmd/podman/report/format_test.go
Jhon Honce c0757374bf Restore "table" --format from V1
* --format "table {{.field..." will print fields out in a table with
  headings.  Table keyword is removed, spaces between fields are
  converted to tabs
* Update parse.MatchesJSONFormat()'s regex to be more inclusive
* Add report.Headers(), obtain all the field names to be used as
  column headers, a map of field name to column headers may be provided
  to override the field names
* Update several commands to use new functions

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-10-02 06:58:02 -07:00

35 lines
821 B
Go

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)
}
})
}
}