forked from TrueCloudLab/restic
options: fail when key is configured twice
This commit is contained in:
parent
946b4f4b86
commit
f587a5f4f0
2 changed files with 17 additions and 0 deletions
|
@ -32,6 +32,11 @@ func Parse(in []string) (Options, error) {
|
|||
if key == "" {
|
||||
return Options{}, errors.Fatalf("empty key is not a valid option")
|
||||
}
|
||||
|
||||
if v, ok := opts[key]; ok && v != value {
|
||||
return Options{}, errors.Fatalf("key %q present more than once", key)
|
||||
}
|
||||
|
||||
opts[key] = value
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,14 @@ var optsTests = []struct {
|
|||
"k2": "more spaces = not evil",
|
||||
},
|
||||
},
|
||||
{
|
||||
[]string{"x=1", "foo=bar", "y=2", "foo=bar"},
|
||||
Options{
|
||||
"x": "1",
|
||||
"y": "2",
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestParseOptions(t *testing.T) {
|
||||
|
@ -58,6 +66,10 @@ var invalidOptsTests = []struct {
|
|||
[]string{"=bar", "bar=baz", "k="},
|
||||
"empty key is not a valid option",
|
||||
},
|
||||
{
|
||||
[]string{"x=1", "foo=bar", "y=2", "foo=baz"},
|
||||
`key "foo" present more than once`,
|
||||
},
|
||||
}
|
||||
|
||||
func TestParseInvalidOptions(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue