From bc3515bd39777634e9efcd2fc9d82b350df3cf24 Mon Sep 17 00:00:00 2001 From: Songmu Date: Wed, 2 Dec 2015 00:36:17 +0900 Subject: [PATCH] add test for doRetire --- main_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/main_test.go b/main_test.go index d0fb09265..50d0e2fe3 100644 --- a/main_test.go +++ b/main_test.go @@ -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 {