diff --git a/cmd/internal-tools/campaign/main.go b/cmd/internal-tools/campaign/main.go index 851dab6..c545c8b 100644 --- a/cmd/internal-tools/campaign/main.go +++ b/cmd/internal-tools/campaign/main.go @@ -15,6 +15,8 @@ import ( "strings" "syscall" "time" + + "github.com/priyanshujain/sanderling/internal/seedspec" ) type config struct { @@ -118,7 +120,7 @@ func parseArguments(arguments []string, stderr io.Writer) (config, error) { return config{}, fmt.Errorf("--run-timeout %s must exceed --duration %s, or every run is killed before it finishes", configuration.runTimeout, configuration.duration) } - seeds, err := parseSeeds(seedSpecification) + seeds, err := seedspec.Parse(seedSpecification) if err != nil { return config{}, fmt.Errorf("--seeds: %w", err) } diff --git a/cmd/internal-tools/campaign/seeds.go b/internal/seedspec/seeds.go similarity index 82% rename from cmd/internal-tools/campaign/seeds.go rename to internal/seedspec/seeds.go index 6245b20..0a79784 100644 --- a/cmd/internal-tools/campaign/seeds.go +++ b/internal/seedspec/seeds.go @@ -1,4 +1,8 @@ -package main +// Package seedspec expands the seed specification a campaign is given into the +// explicit list of seeds it intends to run. The campaign tool and the tools +// that drive it have to read a specification the same way, or a sweep records +// an intent that differs from what ran. +package seedspec import ( "fmt" @@ -6,9 +10,9 @@ import ( "strings" ) -// parseSeeds expands a seed specification such as "1-10,20,30-32" into the +// Parse expands a seed specification such as "1-10,20,30-32" into the // explicit seed list a campaign intends to run. -func parseSeeds(specification string) ([]int64, error) { +func Parse(specification string) ([]int64, error) { trimmed := strings.TrimSpace(specification) if trimmed == "" { return nil, fmt.Errorf("empty seed spec") diff --git a/cmd/internal-tools/campaign/seeds_test.go b/internal/seedspec/seeds_test.go similarity index 76% rename from cmd/internal-tools/campaign/seeds_test.go rename to internal/seedspec/seeds_test.go index e992109..ea6bb02 100644 --- a/cmd/internal-tools/campaign/seeds_test.go +++ b/internal/seedspec/seeds_test.go @@ -1,4 +1,4 @@ -package main +package seedspec import ( "slices" @@ -6,7 +6,7 @@ import ( "testing" ) -func TestParseSeeds_RangesAndLists(t *testing.T) { +func TestParse_RangesAndLists(t *testing.T) { cases := []struct { specification string want []int64 @@ -18,7 +18,7 @@ func TestParseSeeds_RangesAndLists(t *testing.T) { {"4-4", []int64{4}}, } for _, testCase := range cases { - got, err := parseSeeds(testCase.specification) + got, err := Parse(testCase.specification) if err != nil { t.Fatalf("%q: %v", testCase.specification, err) } @@ -28,9 +28,9 @@ func TestParseSeeds_RangesAndLists(t *testing.T) { } } -func TestParseSeeds_RejectsSeedZero(t *testing.T) { +func TestParse_RejectsSeedZero(t *testing.T) { for _, specification := range []string{"0", "1,0,2", "0-3"} { - _, err := parseSeeds(specification) + _, err := Parse(specification) if err == nil { t.Fatalf("%q: expected rejection of seed 0", specification) } @@ -40,9 +40,9 @@ func TestParseSeeds_RejectsSeedZero(t *testing.T) { } } -func TestParseSeeds_RejectsMalformed(t *testing.T) { +func TestParse_RejectsMalformed(t *testing.T) { for _, specification := range []string{"", " ", "abc", "1,,2", "5-1", "1-", "-5", "1-2-3", "1.5", "2,2"} { - if seeds, err := parseSeeds(specification); err == nil { + if seeds, err := Parse(specification); err == nil { t.Errorf("%q: expected error, got %v", specification, seeds) } }