internal: move gotest.Options creation into separate function

The gotest and gojson parsers use the same options (for now). To avoid
duplication the list of parser options is created in a separate
function.
This commit is contained in:
Joël Stemmer 2022-05-21 22:44:38 +01:00
parent dcbbd9fb22
commit b4847b2e36

View File

@ -38,15 +38,9 @@ func (c Config) Run(input io.Reader, output io.Writer) (*gtr.Report, error) {
var p parser var p parser
switch c.Parser { switch c.Parser {
case "gotest": case "gotest":
p = gotest.NewParser( p = gotest.NewParser(c.gotestOptions()...)
gotest.PackageName(c.PackageName),
gotest.TimestampFunc(c.timestampFunc),
)
case "gojson": case "gojson":
p = gotest.NewJSONParser( p = gotest.NewJSONParser(c.gotestOptions()...)
gotest.PackageName(c.PackageName),
gotest.TimestampFunc(c.timestampFunc),
)
default: default:
return nil, fmt.Errorf("invalid parser: %s", c.Parser) return nil, fmt.Errorf("invalid parser: %s", c.Parser)
} }
@ -98,3 +92,10 @@ func (c Config) writeXML(w io.Writer, report gtr.Report) error {
_, err := fmt.Fprintf(w, "\n") _, err := fmt.Fprintf(w, "\n")
return err return err
} }
func (c Config) gotestOptions() []gotest.Option {
return []gotest.Option{
gotest.PackageName(c.PackageName),
gotest.TimestampFunc(c.timestampFunc),
}
}