mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +00:00
options: fail when key is configured twice
This commit is contained in:
parent
946b4f4b86
commit
f587a5f4f0
@ -32,6 +32,11 @@ func Parse(in []string) (Options, error) {
|
|||||||
if key == "" {
|
if key == "" {
|
||||||
return Options{}, errors.Fatalf("empty key is not a valid option")
|
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
|
opts[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,14 @@ var optsTests = []struct {
|
|||||||
"k2": "more spaces = not evil",
|
"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) {
|
func TestParseOptions(t *testing.T) {
|
||||||
@ -58,6 +66,10 @@ var invalidOptsTests = []struct {
|
|||||||
[]string{"=bar", "bar=baz", "k="},
|
[]string{"=bar", "bar=baz", "k="},
|
||||||
"empty key is not a valid option",
|
"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) {
|
func TestParseInvalidOptions(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user