parser

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 26

Documentation

Overview

Package parser contains methods to parse and restructure log output from go testing and terratest.

Index

Constants

This section is empty.

Variables

View Source
var NULL_TEST_RESULT_MARKER = NullTestResultMarker //nolint:revive

NULL_TEST_RESULT_MARKER is deprecated: Use NullTestResultMarker instead.

View Source
var NullTestResultMarker = TestResultMarker{}

NullTestResultMarker is a blank TestResultMarker considered null. Used when peeking or popping an empty stack.

Functions

func EnsureDirectoryExists added in v1.0.0

func EnsureDirectoryExists(logger *logrus.Logger, dirName string) error

EnsureDirectoryExists will only attempt to create the directory if it does not exist.

func GetIndent added in v1.0.0

func GetIndent(data string) string

GetIndent takes a line and returns the indent string Example:

in:  "    --- FAIL: TestSnafu"
out: "    "

func GetTestNameFromResultLine added in v1.0.0

func GetTestNameFromResultLine(text string) string

GetTestNameFromResultLine takes a go testing result line and extracts out the test name Example:

in:  --- FAIL: TestSnafu
out: TestSnafu

func GetTestNameFromStatusLine added in v1.0.0

func GetTestNameFromStatusLine(text string) string

GetTestNameFromStatusLine takes a go testing status line and extracts out the test name Example:

in:  === RUN  TestSnafu
out: TestSnafu

func IsPanicLine added in v1.0.0

func IsPanicLine(text string) bool

IsPanicLine checks if a line of text matches a panic

func IsResultLine added in v1.0.0

func IsResultLine(text string) bool

IsResultLine checks if a line of text matches a test result (begins with "--- FAIL" or "--- PASS")

func IsStatusLine added in v1.0.0

func IsStatusLine(text string) bool

IsStatusLine checks if a line of text matches a test status

func IsSummaryLine added in v1.0.0

func IsSummaryLine(text string) bool

IsSummaryLine checks if a line of text matches the test summary

func SpawnParsers

func SpawnParsers(logger *logrus.Logger, reader io.Reader, outputDir string)

SpawnParsers will spawn the log parser and junit report parsers off of a single reader.

Types

type LogWriter

type LogWriter struct {
	// Lookup represents an open file to a log corresponding to a test (key = test name).
	Lookup map[string]*os.File
	// OutputDir is the directory where log files are written.
	OutputDir string
}

LogWriter manages file handles for writing test log output, keyed by test name.

func (LogWriter) CloseFiles added in v1.0.0

func (logWriter LogWriter) CloseFiles(logger *logrus.Logger)

CloseFiles closes all the file handles in the Lookup dictionary.

func (LogWriter) GetOrCreateFile added in v1.0.0

func (logWriter LogWriter) GetOrCreateFile(logger *logrus.Logger, testName string) (*os.File, error)

GetOrCreateFile will get the corresponding file to a log for the provided test name, or create a new file.

func (LogWriter) WriteLog added in v1.0.0

func (logWriter LogWriter) WriteLog(logger *logrus.Logger, testName string, text string) error

WriteLog will write the provided text to the corresponding log file for the provided test.

type TestResultMarker

type TestResultMarker struct {
	TestName    string
	IndentLevel int
}

TestResultMarker tracks the indentation level of a test result line in go test output. Example: --- FAIL: TestSnafu

--- PASS: TestSnafu/Situation
--- FAIL: TestSnafu/Normal

The three markers for the above in order are: TestResultMarker{TestName: "TestSnafu", IndentLevel: 0} TestResultMarker{TestName: "TestSnafu/Situation", IndentLevel: 4} TestResultMarker{TestName: "TestSnafu/Normal", IndentLevel: 4}

type TestResultMarkerStack

type TestResultMarkerStack []TestResultMarker

TestResultMarkerStack is a stack data structure to store TestResultMarkers.

func (TestResultMarkerStack) IsEmpty added in v1.0.0

func (s TestResultMarkerStack) IsEmpty() bool

IsEmpty will return whether or not the stack is empty.

func (TestResultMarkerStack) Peek added in v1.0.0

Peek will return the top TestResultMarker from the stack, but will not remove it.

func (TestResultMarkerStack) Pop added in v1.0.0

Pop will pop a TestResultMarker object off of the stack, returning the new one with the popped marker. When stack is empty, will return an empty object.

func (TestResultMarkerStack) Push added in v1.0.0

Push will push a TestResultMarker object onto the stack, returning the new one.

func (TestResultMarkerStack) RemoveDedentedTestResultMarkers added in v1.0.0

func (s TestResultMarkerStack) RemoveDedentedTestResultMarkers(currentIndentLevel int) TestResultMarkerStack

RemoveDedentedTestResultMarkers will pop items off of the stack of TestResultMarker objects until the top most item has an indent level less than the current indent level. Assumes that the stack is ordered, in that recently pushed items in the stack have higher indent levels.

Jump to

Keyboard shortcuts

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