mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 11:07:10 +00:00
fix(campaign): name every missing required flag, in flag order
Five required flags ranged as a map, so omitting three told the operator about one, chosen at random.
This commit is contained in:
1 parent
ab4c42601d
commit
2fd67d42f9
2 files changed
+46
-8
No files matched your search
@@ -74,17 +74,26 @@ func parseArguments(arguments []string, stderr io.Writer) (config, error) {
|
|||||||
}
|
}
|
||||||
configuration.extraArguments = flagSet.Args()
|
configuration.extraArguments = flagSet.Args()
|
||||||
|
|
||||||
for name, value := range map[string]string{
|
// Every missing flag is named together, in flag order: stopping at the
|
||||||
"--spec": configuration.specPath,
|
// first turns one rerun into one rerun per missing flag.
|
||||||
"--bundle-id": configuration.bundleID,
|
var missing []error
|
||||||
"--arm": configuration.arm,
|
for _, required := range []struct {
|
||||||
"--seeds": seedSpecification,
|
name string
|
||||||
"--output": configuration.outputDirectory,
|
value string
|
||||||
}{
|
}{
|
||||||
if value == "" {
|
{"--spec", configuration.specPath},
|
||||||
return config{}, fmt.Errorf("%s is required", name)
|
{"--bundle-id", configuration.bundleID},
|
||||||
|
{"--arm", configuration.arm},
|
||||||
|
{"--seeds", seedSpecification},
|
||||||
|
{"--output", configuration.outputDirectory},
|
||||||
|
} {
|
||||||
|
if required.value == "" {
|
||||||
|
missing = append(missing, fmt.Errorf("%s is required", required.name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := errors.Join(missing...); err != nil {
|
||||||
|
return config{}, err
|
||||||
|
}
|
||||||
switch configuration.platform {
|
switch configuration.platform {
|
||||||
case "android", "ios", "web":
|
case "android", "ios", "web":
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -71,6 +71,35 @@ func TestParseArguments_Rejections(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Three flags missing is one rerun, not three: the operator is told about all
|
||||||
|
// of them at once, in flag order, whatever order the check happened to walk.
|
||||||
|
func TestParseArguments_NamesEveryMissingRequiredFlagInFlagOrder(t *testing.T) {
|
||||||
|
_, err := parseArguments(
|
||||||
|
[]string{"--bundle-id", "a", "--seeds", "1", "--max-steps", "10"},
|
||||||
|
io.Discard,
|
||||||
|
)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("got no error, want every missing flag named")
|
||||||
|
}
|
||||||
|
message := err.Error()
|
||||||
|
previous := -1
|
||||||
|
for _, name := range []string{"--spec", "--arm", "--output"} {
|
||||||
|
at := strings.Index(message, name)
|
||||||
|
if at < 0 {
|
||||||
|
t.Fatalf("got %q, want %s named", message, name)
|
||||||
|
}
|
||||||
|
if at < previous {
|
||||||
|
t.Errorf("got %q, want the flags named in flag order", message)
|
||||||
|
}
|
||||||
|
previous = at
|
||||||
|
}
|
||||||
|
for _, supplied := range []string{"--bundle-id", "--seeds"} {
|
||||||
|
if strings.Contains(message, supplied) {
|
||||||
|
t.Errorf("got %q, want the supplied %s left out", message, supplied)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRunArguments_PlatformDeviceFlagAndPassthrough(t *testing.T) {
|
func TestRunArguments_PlatformDeviceFlagAndPassthrough(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
platform string
|
platform string
|
||||||
|
|||||||
Reference in new issue
Block a user