Skip to content

Commit

Permalink
ParsePathSpec: Returning *PathSpec instead of PathSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Hinderberger committed Jun 7, 2024
1 parent d2e2f3b commit a51fab2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions pkg/lib/util/path_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,27 @@ type PathSpec struct {
//
// The string takes the format "[n]@file.json". Invalid path specs
// result in an error.
func ParsePathSpec(s string) (spec PathSpec, err error) {
func ParsePathSpec(s string) (*PathSpec, error) {
var ok bool
var err error
var parallelRuns string
var spec PathSpec

parallelRuns, spec.Path, ok = strings.Cut(s, "@")
if parallelRuns != "" {
spec.ParallelRuns, err = strconv.Atoi(parallelRuns)
if err != nil {
return PathSpec{}, fmt.Errorf("error parsing ParallelRuns of path spec %q: %w", s, err)
return nil, fmt.Errorf("error parsing ParallelRuns of path spec %q: %w", s, err)
}
} else {
spec.ParallelRuns = 1
}

if !ok || spec.Path == "" || spec.ParallelRuns < 0 {
return PathSpec{}, fmt.Errorf("invalid path spec %q", s)
return nil, fmt.Errorf("invalid path spec %q", s)
}

return spec, err
return &spec, err
}

// IsPathSpec is a wrapper around ParsePathSpec that discards the parsed PathSpec.
Expand Down
4 changes: 2 additions & 2 deletions pkg/lib/util/path_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestParsePathSpec(t *testing.T) {
t.Run(testCase.s, func(t *testing.T) {
actual, err := ParsePathSpec(testCase.s)
require.NoError(t, err)
require.Equal(t, testCase.expected, actual)
require.Equal(t, testCase.expected, *actual)
})
}
})
Expand All @@ -67,7 +67,7 @@ func TestParsePathSpec(t *testing.T) {
t.Run(s, func(t *testing.T) {
actual, err := ParsePathSpec(s)
require.Error(t, err)
require.Zero(t, actual)
require.Nil(t, actual)
})
}
})
Expand Down

0 comments on commit a51fab2

Please sign in to comment.