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()},
	}
}

Imported only in test by 14 package(s)

  1. github.com/elastic/beats/metricbeat/mb/parse
  2. github.com/hartfordfive/beats/metricbeat/module/mongodb
  3. github.com/hartfordfive/beats/metricbeat/module/postgresql
  4. gopkg.in/elastic/beats.v5/metricbeat/mb/parse
  5. gopkg.in/elastic/beats.v5/metricbeat/module/apache/status
  6. gopkg.in/elastic/beats.v5/metricbeat/module/system/core
  7. gopkg.in/elastic/beats.v5/metricbeat/module/system/cpu
  8. gopkg.in/elastic/beats.v5/metricbeat/module/system/diskio
  9. gopkg.in/elastic/beats.v5/metricbeat/module/system/filesystem
  10. gopkg.in/elastic/beats.v5/metricbeat/module/system/fsstat
  11. gopkg.in/elastic/beats.v5/metricbeat/module/system/load
  12. gopkg.in/elastic/beats.v5/metricbeat/module/system/memory
  13. gopkg.in/elastic/beats.v5/metricbeat/module/system/network
  14. gopkg.in/elastic/beats.v5/metricbeat/module/system/process

Imports 3 package(s)

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