-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
161 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/csv" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"gotest.tools/gotestsum/testjson" | ||
) | ||
|
||
type noSummaryValue struct { | ||
value testjson.Summary | ||
} | ||
|
||
func newNoSummaryValue() *noSummaryValue { | ||
return &noSummaryValue{value: testjson.SummarizeAll} | ||
} | ||
|
||
func readAsCSV(val string) ([]string, error) { | ||
if val == "" { | ||
return nil, nil | ||
} | ||
return csv.NewReader(strings.NewReader(val)).Read() | ||
} | ||
|
||
func (s *noSummaryValue) Set(val string) error { | ||
v, err := readAsCSV(val) | ||
if err != nil { | ||
return err | ||
} | ||
for _, item := range v { | ||
summary, ok := testjson.NewSummary(item) | ||
if !ok { | ||
return errors.Errorf("value must be one or more of: %s", | ||
testjson.SummarizeAll.String()) | ||
} | ||
s.value -= summary | ||
} | ||
return nil | ||
} | ||
|
||
func (s *noSummaryValue) Type() string { | ||
return "summary" | ||
} | ||
|
||
func (s *noSummaryValue) String() string { | ||
// flip all the bits, since the flag value is the negative of what is stored | ||
return (testjson.SummarizeAll ^ s.value).String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
) | ||
|
||
func TestNoSummaryValue_SetAndString(t *testing.T) { | ||
t.Run("none", func(t *testing.T) { | ||
assert.Equal(t, newNoSummaryValue().String(), "") | ||
}) | ||
t.Run("one", func(t *testing.T) { | ||
value := newNoSummaryValue() | ||
assert.NilError(t, value.Set("output")) | ||
assert.Equal(t, value.String(), "output") | ||
|
||
}) | ||
t.Run("some", func(t *testing.T) { | ||
value := newNoSummaryValue() | ||
assert.NilError(t, value.Set("errors,failed")) | ||
assert.Equal(t, value.String(), "failed,errors") | ||
}) | ||
t.Run("bad value", func(t *testing.T) { | ||
value := newNoSummaryValue() | ||
assert.ErrorContains(t, value.Set("bogus"), "must be one or more of") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters