github.com/mackerelio/mackerel-agent-plugins@v0.89.3/mackerel-plugin-conntrack/lib/cli_test.go (about) 1 package mpconntrack 2 3 import ( 4 "bytes" 5 "fmt" 6 "strings" 7 "testing" 8 ) 9 10 func TestGraphDefinition(t *testing.T) { 11 var conntrack ConntrackPlugin 12 13 graphdef := conntrack.GraphDefinition() 14 if len(graphdef) != 1 { 15 t.Errorf("GetTempfilename: %d should be 1", len(graphdef)) 16 } 17 } 18 19 func TestCLI_Run(t *testing.T) { 20 outStream, errStream := new(bytes.Buffer), new(bytes.Buffer) 21 cli := &CLI{outStream: outStream, errStream: errStream} 22 args := strings.Split("mackerel-plugin-conntrack -version", " ") 23 24 status := cli.Run(args) 25 if status != ExitCodeOK { 26 t.Errorf("ExitStatus=%d, want %d", status, ExitCodeOK) 27 } 28 29 expected := fmt.Sprintf("mackerel-plugin-conntrack version %s", Version) 30 if !strings.Contains(errStream.String(), expected) { 31 t.Errorf("Output=%q, want %q", errStream.String(), expected) 32 } 33 34 args = strings.Split("mackerel-plugin-conntrack -unknown", " ") 35 36 status = cli.Run(args) 37 if status != ExitCodeParseFlagError { 38 t.Errorf("ExitStatus=%d, want %d", status, ExitCodeOK) 39 } 40 41 }