func testMain(t *testing.T, code string, endpoint string, serverType ServerType) { // Build the fake snmpwalk for test src := makeFakeSNMPSrc(code) defer os.Remove(src) buildFakeSNMPCmd(src) defer os.Remove("./snmpwalk") envPathOrigin := os.Getenv("PATH") // Refer to the fake snmpwalk os.Setenv("PATH", ".") defer os.Setenv("PATH", envPathOrigin) l := &LeoFS{ Servers: []string{endpoint}, } var acc testutil.Accumulator err := l.Gather(&acc) require.NoError(t, err) floatMetrics := KeyMapping[serverType] for _, metric := range floatMetrics { assert.True(t, acc.HasFloatValue(metric), metric) } }
func TestPostgresqlGeneratesMetrics(t *testing.T) { if testing.Short() { t.Skip("Skipping integration test in short mode") } p := &Postgresql{ Servers: []*Server{ { Address: fmt.Sprintf("host=%s user=postgres sslmode=disable", testutil.GetLocalHost()), Databases: []string{"postgres"}, }, }, } var acc testutil.Accumulator err := p.Gather(&acc) require.NoError(t, err) intMetrics := []string{ "xact_commit", "xact_rollback", "blks_read", "blks_hit", "tup_returned", "tup_fetched", "tup_inserted", "tup_updated", "tup_deleted", "conflicts", "temp_files", "temp_bytes", "deadlocks", } floatMetrics := []string{ "blk_read_time", "blk_write_time", } for _, metric := range intMetrics { assert.True(t, acc.HasIntValue(metric)) } for _, metric := range floatMetrics { assert.True(t, acc.HasFloatValue(metric)) } }