Skip to content

Commit 797fbd9

Browse files
author
Matthew Fisher
committed
Merge pull request #415 from bacongobbler/error-on-malformed-config
fix(client): exit 1 with malformed config:set input
2 parents 77d02f7 + 1de42fb commit 797fbd9

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

client/cmd/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ func parseConfig(configVars []string) map[string]interface{} {
238238
configMap[captures[1]] = captures[2]
239239
} else {
240240
fmt.Printf("'%s' does not match the pattern 'key=var', ex: MODE=test\n", config)
241+
os.Exit(1)
241242
}
242243
}
243244

client/cmd/config_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
"os/exec"
6+
"testing"
7+
)
8+
9+
// Fancy way for testing processes exit unsuccessfully.
10+
// See https://talks.golang.org/2014/testing.slide#23
11+
func TestParseConfig(t *testing.T) {
12+
if os.Getenv("TEST_BAD_CONFIG") == "1" {
13+
parseConfig([]string{"FOO=bar", "CAR star"})
14+
return
15+
}
16+
cmd := exec.Command(os.Args[0], "-test.run=TestParseConfig")
17+
cmd.Env = append(os.Environ(), "TEST_BAD_CONFIG=1")
18+
err := cmd.Run()
19+
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
20+
return
21+
}
22+
t.Fatalf("process ran with err %v, want exit status 1", err)
23+
}

0 commit comments

Comments
 (0)