2020-10-29 16:31:14 +00:00
|
|
|
package inspect
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFormat(t *testing.T) {
|
|
|
|
m := []typeStats{{
|
|
|
|
Name: "msg",
|
|
|
|
Sum: 1,
|
|
|
|
Count: 2,
|
|
|
|
}}
|
2020-11-05 16:40:02 +00:00
|
|
|
mkv := []typeStats{{
|
|
|
|
Name: "msgKV",
|
|
|
|
Sum: 1,
|
|
|
|
Count: 2,
|
|
|
|
}}
|
2020-10-29 16:31:14 +00:00
|
|
|
info := OutputFormat{
|
|
|
|
Meta: &MetadataInfo{
|
|
|
|
ID: "one",
|
|
|
|
Size: 2,
|
|
|
|
Index: 3,
|
|
|
|
Term: 4,
|
|
|
|
Version: 1,
|
|
|
|
},
|
2020-11-05 16:40:02 +00:00
|
|
|
Stats: m,
|
|
|
|
StatsKV: mkv,
|
|
|
|
TotalSize: 1,
|
|
|
|
TotalSizeKV: 1,
|
2020-10-29 16:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
formatters := map[string]Formatter{
|
|
|
|
"pretty": newPrettyFormatter(),
|
|
|
|
// the JSON formatter ignores the showMeta
|
|
|
|
"json": newJSONFormatter(),
|
|
|
|
}
|
|
|
|
|
|
|
|
for fmtName, formatter := range formatters {
|
|
|
|
t.Run(fmtName, func(t *testing.T) {
|
2020-11-10 17:18:21 +00:00
|
|
|
actual, err := formatter.Format(&info)
|
2020-10-29 16:31:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
gName := fmt.Sprintf("%s", fmtName)
|
|
|
|
|
|
|
|
expected := golden(t, gName, actual)
|
|
|
|
require.Equal(t, expected, actual)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|