From a51fab21bd05a5e68ff0a3e7b12178ae927071f7 Mon Sep 17 00:00:00 2001 From: Lucas Hinderberger Date: Fri, 7 Jun 2024 16:59:22 +0200 Subject: [PATCH] ParsePathSpec: Returning *PathSpec instead of PathSpec --- pkg/lib/util/path_util.go | 10 ++++++---- pkg/lib/util/path_util_test.go | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/lib/util/path_util.go b/pkg/lib/util/path_util.go index 1fc57f3..310ae3b 100644 --- a/pkg/lib/util/path_util.go +++ b/pkg/lib/util/path_util.go @@ -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. diff --git a/pkg/lib/util/path_util_test.go b/pkg/lib/util/path_util_test.go index 4097db4..32bfc76 100644 --- a/pkg/lib/util/path_util_test.go +++ b/pkg/lib/util/path_util_test.go @@ -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) }) } }) @@ -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) }) } })