mirror of
https://github.com/kopia/kopia.git
synced 2026-09-13 05:37:46 -04:00
The --parallel flag was declared with kingpin .IntVar on 12 commands, which accepted negative values and led to a panic at runtime (e.g. `snapshot migrate --parallel=-1`). Declare the --parallel family as uint so kingpin rejects negative input at parse time. The uint->int conversion the callee APIs need is done through a small helper . Add CLI test that asserts the rejection message (a bare failure check passed even without the fix since the commands also fail with no repository connected). Parse via ParseFloat like kingpin's built-in int flag so the only behavior change is rejecting negatives.
34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/kopia/kopia/tests/testenv"
|
|
)
|
|
|
|
// TestNegativeParallelRejected verifies that a negative --parallel value is
|
|
// rejected at flag-parse time and returns an error identifying the bad value
|
|
// rather than panicking once the command runs.
|
|
func TestNegativeParallelRejected(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
env := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
|
|
|
|
for _, args := range [][]string{
|
|
{"snapshot", "migrate", "--parallel=-1", "--all"},
|
|
{"content", "verify", "--parallel=-1"},
|
|
} {
|
|
_, _, err := env.Run(t, true, args...)
|
|
// check rejection message so the test fails if
|
|
// the flag ever stops validating, otherwise a
|
|
// bare "command failed" check would pass
|
|
// since these commands fail regardless given that
|
|
// no repository is connected.
|
|
require.ErrorContains(t, err, "invalid syntax",
|
|
"'kopia %v' should fail parsing the negative value", strings.Join(args, " "))
|
|
}
|
|
}
|