github.com/mackerelio/mackerel-agent-plugins@v0.89.3/mackerel-plugin-proc-fd/lib/proc_fd_test.go (about) 1 package mpprocfd 2 3 import "testing" 4 5 func TestGraphDefinition(t *testing.T) { 6 var fd ProcfdPlugin 7 8 graph := fd.GraphDefinition() 9 if actual := len(graph); actual != 1 { 10 t.Errorf("GraphDefinition(): %d should be 1", actual) 11 } 12 } 13 14 type TestOpenFd struct{} 15 16 func (o TestOpenFd) getNumOpenFileDesc() (map[string]uint64, error) { 17 return map[string]uint64{ 18 "8273": 90, 19 "8274": 100, 20 "8275": 95, 21 }, nil 22 } 23 24 func TestFetchMetrics(t *testing.T) { 25 openFd = TestOpenFd{} 26 var fd ProcfdPlugin 27 stat, _ := fd.FetchMetrics() 28 29 if actual := stat["max_fd"].(uint64); actual != 100 { 30 t.Errorf("FetchMetrics(): max_fd(%d) should be 100", actual) 31 } 32 }