Skip to content

Commit

Permalink
jlog: add a tiny bit more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jrockway committed Jul 9, 2022
1 parent cae9e59 commit 4183ae0
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion cmd/internal/jlog/jlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"strings"
"testing"

"github.com/jessevdk/go-flags"
"github.com/jrockway/json-logs/pkg/parse"
)

func TestDefaults(t *testing.T) {
func TestEmpty(t *testing.T) {
if _, err := NewInputSchema(Input{}); err != nil {
t.Errorf("new input schema: %v", err)
}
Expand All @@ -19,6 +20,59 @@ func TestDefaults(t *testing.T) {
}
}

func TestFlagParsing(t *testing.T) {
testData := []struct {
name string
flags []string
}{
{
name: "default",
},
{
name: "short",
flags: []string{
"-r", "-t", "rfc3339nano", "-s", "-p", "foo", "-H", "bar",
"-A", "1", "-B", "2", "-C", "3",
"-g", ".",
"-S", "k",
"-e", "select(true)",
"-M", "-c",
"-l",
},
},
}

for _, test := range testData {
t.Run(test.name, func(t *testing.T) {
var gen General
var in Input
var out Output
fp := flags.NewParser(nil, flags.HelpFlag)
if _, err := fp.AddGroup("Input Schema", "", &in); err != nil {
t.Errorf("add group: %v", err)
}
if _, err := fp.AddGroup("Output Format", "foo", &out); err != nil {
t.Errorf("add group: %v", err)
}
if _, err := fp.AddGroup("General", "bar", &gen); err != nil {
t.Errorf("add group: %v", err)
}
if _, err := fp.ParseArgs(test.flags); err != nil {
t.Errorf("parse args: %v", err)
}
if _, err := NewInputSchema(in); err != nil {
t.Errorf("new input schema: %v", err)
}
if _, err := NewOutputFormatter(out, gen); err != nil {
t.Errorf("new output schema: %v", err)
}
if _, err := NewFilterScheme(gen); err != nil {
t.Errorf("new filter scheme: %v", err)
}
})
}
}

func TestPrintOutputSummary(t *testing.T) {
w := new(strings.Builder)
PrintOutputSummary(Output{}, parse.Summary{}, w)
Expand Down

0 comments on commit 4183ae0

Please sign in to comment.