Documentation ¶
Overview ¶
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()}, } }
Index ¶
- func CreateFullEvent(ms mb.MetricSet, metricSetData common.MapStr) common.MapStr
- func NewEventFetcher(t testing.TB, config interface{}) mb.EventFetcher
- func NewEventsFetcher(t testing.TB, config interface{}) mb.EventsFetcher
- func NewPushMetricSet(t testing.TB, config interface{}) mb.PushMetricSet
- func RunPushMetricSet(duration time.Duration, metricSet mb.PushMetricSet) ([]common.MapStr, []error)
- func WriteEvent(f mb.EventFetcher, t testing.TB) error
- func WriteEventToDataJSON(t testing.TB, fullEvent common.MapStr)
- func WriteEvents(f mb.EventsFetcher, t testing.TB) error
- type TestModule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateFullEvent ¶
CreateFullEvent builds a full event given the data generated by a MetricSet. This simulates the output of Metricbeat as if it were 2016-05-23T08:05:34.853Z and the hostname is host.example.com.
func NewEventFetcher ¶
func NewEventFetcher(t testing.TB, config interface{}) mb.EventFetcher
NewEventFetcher instantiates a new EventFetcher using the given configuration. The ModuleFactory and MetricSetFactory are obtained from the global Registry.
func NewEventsFetcher ¶
func NewEventsFetcher(t testing.TB, config interface{}) mb.EventsFetcher
NewEventsFetcher instantiates a new EventsFetcher using the given configuration. The ModuleFactory and MetricSetFactory are obtained from the global Registry.
func NewPushMetricSet ¶
func NewPushMetricSet(t testing.TB, config interface{}) mb.PushMetricSet
NewPushMetricSet instantiates a new PushMetricSet using the given configuration. The ModuleFactory and MetricSetFactory are obtained from the global Registry.
func RunPushMetricSet ¶
func RunPushMetricSet(duration time.Duration, metricSet mb.PushMetricSet) ([]common.MapStr, []error)
RunPushMetricSet run the given push metricset for the specific amount of time and returns all of the events and errors that occur during that period.
func WriteEvent ¶
func WriteEvent(f mb.EventFetcher, t testing.TB) error
WriteEvent fetches a single event writes the output to a ./_meta/data.json file.
func WriteEventToDataJSON ¶
WriteEventToDataJSON writes the given event as "pretty" JSON to a ./_meta/data.json file. If the -data CLI flag is unset or false then the method is a no-op.
func WriteEvents ¶
func WriteEvents(f mb.EventsFetcher, t testing.TB) error
WriteEvents fetches events and writes the first event to a ./_meta/data.json file.
Types ¶
type TestModule ¶
type TestModule struct { ModName string ModConfig mb.ModuleConfig RawConfig *common.Config }
func NewTestModule ¶
func NewTestModule(t testing.TB, config interface{}) *TestModule
func (*TestModule) Config ¶
func (m *TestModule) Config() mb.ModuleConfig
func (*TestModule) Name ¶
func (m *TestModule) Name() string
func (*TestModule) UnpackConfig ¶
func (m *TestModule) UnpackConfig(to interface{}) error