top

Package testing provides utility functions for testing Module and MetricSet implementations.

MetricSet Example

This is an example showing how to use this package to test a MetricSet. By using these methods you ensure the MetricSet is instantiated in the same way that Metricbeat does it and with the same validations.

package mymetricset_test

import (
	mbtest "github.com/elastic/beats/metricbeat/mb/testing"
)

func TestFetch(t *testing.T) {
	f := mbtest.NewEventFetcher(t, getConfig())
	event, err := f.Fetch()
	if err != nil {
		t.Fatal(err)
	}

	t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), event)

	// Test event attributes...
}

func getConfig() map[string]interface{} {
	return map[string]interface{}{
		"module":     "mymodule",
		"metricsets": []string{"status"},
		"hosts":      []string{mymodule.GetHostFromEnv()},
	}
}

Imports 3 package(s) ΒΆ

  1. github.com/stretchr/testify/assert
  2. github.com/elastic/beats/libbeat/common
  3. github.com/elastic/beats/metricbeat/mb