testcase

package
v0.0.0-...-aab34d4 Latest Latest
Warning

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

Go to latest
Published: May 27, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComparisonError

type ComparisonError struct {
	ActualCount   int
	ExpectedCount int
	Mismatches    []MismatchedEvent
}

ComparisonError indicates that there was a mismatch when the results of a test case was compared against the test case definition.

func (ComparisonError) Error

func (e ComparisonError) Error() string

type MismatchedEvent

type MismatchedEvent struct {
	Actual   logstash.Event
	Expected logstash.Event
	Index    int
}

MismatchedEvent holds a single tuple of actual and expected events for a particular index in the list of events for a test case.

type TestCase

type TestCase struct {
	// InputLines contains the lines of input that should be fed
	// to the Logstash process.
	InputLines []string `json:"input"`

	// ExpectedEvents contains a slice of expected events to be
	// compared to the actual events produced by the Logstash
	// process.
	ExpectedEvents []logstash.Event `json:"expected"`

	// Description contains an optional description of the test case
	// which will be printed while the tests are executed.
	Description string `json:"description"`
}

TestCase is a pair of an input line that should be fed into the Logstash process and an expected event which is compared to the actual event produced by the Logstash process.

type TestCaseSet

type TestCaseSet struct {
	// File is the absolute path to the file from which this
	// test case was read.
	File string `json:"-"`

	// Codec names the Logstash codec that should be used when
	// events are read. This is normally "line" or "json_lines".
	Codec string `json:"codec"`

	// IgnoredFields contains a list of fields that will be
	// deleted from the events that Logstash returns before
	// they're compared to the events in ExpectedEevents.
	//
	// This can be used for skipping fields that Logstash
	// populates with unpredictable contents (hostnames or
	// timestamps) that can't be hard-wired into the test case
	// file.
	//
	// It's also useful for the @version field that Logstash
	// always adds with a constant value so that one doesn't have
	// to include that field in every event in ExpectedEvents.
	IgnoredFields []string `json:"ignore"`

	// InputFields contains a mapping of fields that should be
	// added to input events, like "type" or "tags". The map
	// values may be scalar values or arrays of scalar
	// values. This is often important since filters typically are
	// configured based on the event's type or its tags.
	InputFields logstash.FieldSet `json:"fields"`

	// InputLines contains the lines of input that should be fed
	// to the Logstash process.
	InputLines []string `json:"input"`

	// ExpectedEvents contains a slice of expected events to be
	// compared to the actual events produced by the Logstash
	// process.
	ExpectedEvents []logstash.Event `json:"expected"`

	// TestCases is a slice of test cases, which include at minimum
	// a pair of an input and an expected event
	// Optionally other information regarding the test case
	// may be supplied.
	TestCases []TestCase `json:"testcases"`
	// contains filtered or unexported fields
}

TestCaseSet contains the configuration of a Logstash filter test case. Most of the fields are supplied by the user via a JSON file.

func DiscoverTests

func DiscoverTests(path string) ([]TestCaseSet, error)

DiscoverTests reads a test case JSON file and returns a slice of TestCase structs or, if the input path is a directory, reads all .json files in that directorory and returns them as TestCase structs.

func New

func New(reader io.Reader) (*TestCaseSet, error)

New reads a test case configuration from a reader and returns a TestCase. Defaults to a "line" codec and ignoring the @version field. If the configuration being read lists additional fields to ignore those will be ignored in addition to @version.

func NewFromFile

func NewFromFile(path string) (*TestCaseSet, error)

NewFromFile reads a test case configuration from an on-disk file.

func (*TestCaseSet) Compare

func (tcs *TestCaseSet) Compare(events []logstash.Event, quiet bool, diffCommand []string) error

Compare compares a slice of events against the expected events of this test case. Each event is written pretty-printed to a temporary file and the two files are passed to "diff -u". If quiet is true, the progress messages normally written to stderr will be emitted and the output of the diff program will be discarded.

Jump to

Keyboard shortcuts

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