github.com/mackerelio/mackerel-agent-plugins@v0.89.3/mackerel-plugin-haproxy/lib/haproxy_test.go (about)

     1  package mphaproxy
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestGraphDefinition(t *testing.T) {
    12  	var haproxy HAProxyPlugin
    13  
    14  	graphdef := haproxy.GraphDefinition()
    15  	if len(graphdef) != 3 {
    16  		t.Errorf("GetTempfilename: %d should be 3", len(graphdef))
    17  	}
    18  }
    19  
    20  func TestParse(t *testing.T) {
    21  	var haproxy HAProxyPlugin
    22  	stub := `# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,
    23  hastats,FRONTEND,,,1,1,64,43,7061,15994,0,0,0,,,,,OPEN,,,,,,,,,1,1,0,,,,0,2,0,2,,,,0,10,0,15,17,0,,2,2,43,,,0,0,0,0,,,,,,,,
    24  hastats,BACKEND,0,0,0,1,7,17,7061,15994,0,0,,17,0,0,0,UP,0,0,0,,0,1543,0,,1,1,0,,0,,1,0,,1,,,,0,0,0,0,17,0,,,,,0,0,0,0,0,0,0,,,0,0,0,0,
    25  `
    26  
    27  	haproxyStats := bytes.NewBufferString(stub)
    28  
    29  	stat, err := haproxy.parseStats(haproxyStats)
    30  	fmt.Println(stat)
    31  	assert.Nil(t, err)
    32  	// HaProxy Stats
    33  	assert.EqualValues(t, stat["sessions"], 17)
    34  	assert.EqualValues(t, stat["bytes_in"], 7061)
    35  	assert.EqualValues(t, stat["bytes_out"], 15994)
    36  	assert.EqualValues(t, stat["connection_errors"], 17)
    37  }