mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
refactor(seedspec): move seed spec parsing out of the campaign command
the campaign tool and the sweep tools that drive it have to read a seed specification the same way, or a sweep records an intent that differs from what ran. parseSeeds becomes seedspec.Parse with no behaviour change.
This commit is contained in:
1 parent
7823f53453
commit
a28178337c
3 files changed
+17
-11
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user