Skip to content

Commit

Permalink
add test for doRetire
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Dec 1, 2015
1 parent 76de115 commit bc3515b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions main_test.go
Expand Up @@ -112,6 +112,39 @@ func TestDetectForce(t *testing.T) {
}
}

func TestResolveConfigForRetire(t *testing.T) {
confFile, err := ioutil.TempFile("", "mackerel-config-test")
if err != nil {
t.Fatalf("Could not create temprary config file for test")
}
confFile.WriteString(`apikey="DUMMYAPIKEY"
`)
confFile.Sync()
confFile.Close()
defer os.Remove(confFile.Name())

// Allow accepting unnecessary options, pidfile, diagnostic and role.
// Because, these options are potentially passed in initd script by using $OTHER_OPTS.
argv := []string{
"-conf=" + confFile.Name(),
"-apibase=https://mackerel.io",
"-pidfile=hoge",
"-root=hoge",
"-verbose",
"-diagnostic",
"-apikey=hogege",
"-role=hoge:fuga",
}

conf, force, err := resolveConfigForRetire(argv)
if force {
t.Errorf("force should be false")
}
if conf.Apikey != "hogege" {
t.Errorf("Apikey should be 'hogege'")
}
}

func TestCreateAndRemovePidFile(t *testing.T) {
file, err := ioutil.TempFile("", "")
if err != nil {
Expand Down

0 comments on commit bc3515b

Please sign in to comment.