github.com/mackerelio/mackerel-agent-plugins@v0.89.3/mackerel-plugin-unicorn/lib/unicorn_memory_test.go (about) 1 package mpunicorn 2 3 import "testing" 4 5 type TestWorkersMemoryPipedCommands struct{} 6 7 func (r TestWorkersMemoryPipedCommands) Output(commands ...[]string) ([]byte, error) { 8 return []byte("3321016320\n"), nil 9 } 10 11 func TestWorkersMemory(t *testing.T) { 12 pipedCommands = TestWorkersMemoryPipedCommands{} 13 expectedMemory := "3321016320" 14 m, _ := workersMemory() 15 if m != expectedMemory { 16 t.Errorf("workersMemory: expected %s but got %s", expectedMemory, m) 17 } 18 } 19 20 type TestMasterMemoryPipedCommands struct{} 21 22 func (r TestMasterMemoryPipedCommands) Output(commands ...[]string) ([]byte, error) { 23 return []byte("114636\n"), nil 24 } 25 26 func TestMasterMemory(t *testing.T) { 27 pipedCommands = TestMasterMemoryPipedCommands{} 28 expectedMemory := "114636" 29 m, _ := masterMemory() 30 if m != expectedMemory { 31 t.Errorf("masterMemory: expected %s but got %s", expectedMemory, m) 32 } 33 } 34 35 type TestWorkersMemoryAvgPipedCommands struct{} 36 37 func (r TestWorkersMemoryAvgPipedCommands) Output(commands ...[]string) ([]byte, error) { 38 return []byte("204277504\n"), nil 39 } 40 41 func TestWorkersMemoryAvg(t *testing.T) { 42 pipedCommands = TestWorkersMemoryAvgPipedCommands{} 43 expectedMemory := "204277504" 44 m, _ := workersMemoryAvg() 45 if m != expectedMemory { 46 t.Errorf("workersMemoryAvg: expected %s but got %s", expectedMemory, m) 47 } 48 }