testing

package
v5.6.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2017 License: Apache-2.0 Imports: 11 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 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 WriteEvent

func WriteEvent(f mb.EventFetcher, t *testing.T) error

func WriteEvents

func WriteEvents(f mb.EventsFetcher, t *testing.T) error

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