testing

package
v6.1.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFullEvent

func CreateFullEvent(ms mb.MetricSet, metricSetData common.MapStr) beat.Event

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 NewReportingMetricSet

func NewReportingMetricSet(t testing.TB, config interface{}) mb.ReportingMetricSet

func ReportingFetch

func ReportingFetch(metricSet mb.ReportingMetricSet) ([]common.MapStr, []error)

ReportingFetch runs the given reporting metricset and returns all of the events and errors that occur during that period.

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

func WriteEventToDataJSON(t testing.TB, fullEvent beat.Event)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL