Rework fakes to allow additional arguments

This commit is contained in:
Gareth Smith 2017-11-24 12:15:39 +00:00
parent e7bb1e8df9
commit a04f00234e
2 changed files with 24 additions and 9 deletions

View File

@ -19,10 +19,18 @@ func main() {
"--storage-backend=etcd3", "--storage-backend=etcd3",
"--etcd-servers=the etcd url", "--etcd-servers=the etcd url",
} }
numExpectedArgs := len(expectedArgs)
numGivenArgs := len(os.Args) - 1
for i, arg := range os.Args[1:] { if numGivenArgs < numExpectedArgs {
if arg != expectedArgs[i] { fmt.Printf("Expected at least %d args, only got %d\n", numExpectedArgs, numGivenArgs)
fmt.Printf("Expected arg %s, got arg %s", expectedArgs[i], arg) os.Exit(2)
}
for i, arg := range expectedArgs {
givenArg := os.Args[i+1]
if arg != givenArg {
fmt.Printf("Expected arg %s, got arg %s\n", arg, givenArg)
os.Exit(1) os.Exit(1)
} }
} }

View File

@ -8,18 +8,25 @@ import (
func main() { func main() {
expectedArgs := []string{ expectedArgs := []string{
"--debug",
"--advertise-client-urls", "--advertise-client-urls",
"our etcd url", "our etcd url",
"--data-dir",
"our data directory",
"--listen-client-urls", "--listen-client-urls",
"our etcd url", "our etcd url",
"--debug", "--data-dir",
}
numExpectedArgs := len(expectedArgs)
numGivenArgs := len(os.Args) - 1
if numGivenArgs < numExpectedArgs {
fmt.Printf("Expected at least %d args, only got %d\n", numExpectedArgs, numGivenArgs)
os.Exit(2)
} }
for i, arg := range os.Args[1:] { for i, arg := range expectedArgs {
if arg != expectedArgs[i] { givenArg := os.Args[i+1]
fmt.Printf("Expected arg %s, got arg %s", expectedArgs[i], arg) if arg != givenArg {
fmt.Printf("Expected arg %s, got arg %s\n", arg, givenArg)
os.Exit(1) os.Exit(1)
} }
} }