logtesting

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualTimestamp

func EqualTimestamp(t *testing.T, expect, actual time.Time, msgAndArgs ...interface{})

EqualTimestamp is a helper that checks timestamps for equality with human readable message

func JSON

func JSON() jsoniter.API

JSON returns a jsoniter.API to be used for parser tests. The returned API forces omitempty to all fields and relies on global tcodec registration. It does not include conversion of output timestamp formats to make it easier to write test cases.

func RunTests

func RunTests(t *testing.T, tests ...TestCase)

RunTests is a helper that runs all test cases in sequence

func RunTestsFromYAML

func RunTestsFromYAML(t *testing.T, resolve logtypes.Finder, filename string)

RunTestsFromYAML reads all test cases in a YAML file and runs them.

func TestRegisteredParser

func TestRegisteredParser(t *testing.T, resolve logtypes.Finder, logType, input string, expect ...string)

TestRegisteredParser is a helper to run a test for a registered log parser

func TestResult

func TestResult(t *testing.T, expect string, actual *pantherlog.Result, indicators ...pantherlog.FieldID)

Checks that `actual` is a parser result matching `expect` If expect.RowID is empty it checks if actual has non-empty RowID If expect.EventTime is zero it checks if actual.EventTime equals actual.ParseTime If expect.ParseTime is zero it checks if actual.ParseTime is non-zero Otherwise equality is checked strictly

Types

type TestCase

type TestCase struct {
	Name    string          `json:"name" yaml:"name"`
	Input   string          `json:"input" yaml:"input"`
	Result  string          `json:"result" yaml:"result"`
	Results []string        `json:"results" yaml:"results"`
	LogType string          `json:"logType" yaml:"logType"`
	Resolve logtypes.Finder `json:"-" yaml:"-"`
}

TestCase is a test case validating the input and output for a parser TODO: add fields to allow test cases to test that a parser produces errors

func (*TestCase) Run

func (c *TestCase) Run(t *testing.T)

Run runs a test case

Jump to

Keyboard shortcuts

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