testreporters

package
v1.34.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 18 Imported by: 5

Documentation

Overview

Package testreporters holds all the tools necessary to report on tests that are run utilizing the testsetups package

Index

Constants

View Source
const (
	// DefaultArtifactsDir default artifacts dir
	DefaultArtifactsDir string = "logs"
)

Variables

View Source
var (
	OneLogAtLogLevelErr       = "found log at level"
	MultipleLogsAtLogLevelErr = "found too many logs at level"
)
View Source
var (
	SlackAPIKey  = os.Getenv(config.EnvVarSlackKey)
	SlackChannel = os.Getenv(config.EnvVarSlackChannel)
	SlackUserID  = os.Getenv(config.EnvVarSlackUser)
)

Values for reporters to use slack to notify user of test end

Functions

func CommonSlackNotificationBlocks added in v1.4.10

func CommonSlackNotificationBlocks(
	headerText, namespace,
	reportCsvLocation string,
) []slack.Block

func FindAllLogFilesToScan added in v1.28.11

func FindAllLogFilesToScan(directoryPath string, partialFilename string) (logFilesToScan []*os.File, err error)

FindAllLogFilesToScan walks through log files pulled from all pods, and gets all chainlink node logs

func MkdirIfNotExists added in v1.4.10

func MkdirIfNotExists(dirName string) error

creates a directory if it doesn't already exist

func ScanLogLine added in v1.28.15

func ScanLogLine(log zerolog.Logger, jsonLogLine string, failingLogLevel zapcore.Level, foundSoFar, failureThreshold uint, allowedMessages []AllowedLogMessage) (uint, error)

ScanLogLine scans a log line for a failing log level, returning the number of failing logs found so far. It returns an error if the failure threshold is reached or if any panic is found or if there's no log level found. It also takes a list of allowed messages that are ignored if found.

func SendReport added in v1.4.10

func SendReport(t *testing.T, namespace string, logsPath string, optionalTestReporter TestReporter, grafanaUrlProvider GrafanaURLProvider) error

SendReport writes a test report and sends a Slack notification if the test provides one

func SendSlackMessage added in v1.4.10

func SendSlackMessage(slackClient *slack.Client, msgOptions ...slack.MsgOption) (string, error)

Sends a slack message, and returns an error and the message timestamp

func SlackNotifyBlocks added in v1.7.2

func SlackNotifyBlocks(headerText, namespace string, msgtext []string) []slack.Block

SlackNotifyBlocks creates a slack payload and writes into the specified json

func UploadSlackFile added in v1.4.10

func UploadSlackFile(slackClient *slack.Client, uploadParams slack.FileUploadParameters) error

Uploads a slack file to the designated channel using the API key

func VerifyLogFile added in v1.28.11

func VerifyLogFile(file *os.File, failingLogLevel zapcore.Level, failureThreshold uint, allowedMessages ...AllowedLogMessage) error

VerifyLogFile verifies that a log file does not contain any logs at a level higher than the failingLogLevel. If it does, it will return an error. It also allows for a list of AllowedLogMessages to be passed in, which will be ignored if found in the log file. The failureThreshold is the number of logs at the failingLogLevel or higher that can be found before the function returns an error.

func WriteTeardownLogs added in v1.4.10

func WriteTeardownLogs(
	t *testing.T,
	env *environment.Environment,
	optionalTestReporter TestReporter,
	failingLogLevel zapcore.Level,
	grafanaUrlProvider GrafanaURLProvider,
) error

WriteTeardownLogs attempts to download the logs of all ephemeral test deployments onto the test runner, also writing a test report if one is provided. A failing log level also enables you to fail a test based on what level logs the Chainlink nodes have thrown during their test.

Types

type AllowedLogMessage added in v1.28.11

type AllowedLogMessage struct {
	// contains filtered or unexported fields
}

AllowedLogMessage is a log message that might be thrown by a Chainlink node during a test, but is not a concern

func NewAllowedLogMessage added in v1.28.11

func NewAllowedLogMessage(message string, reason string, level zapcore.Level, logWhenFound WarnAboutAllowedMsgs) AllowedLogMessage

NewAllowedLogMessage creates a new AllowedLogMessage. If logWhenFound is true, the log message will be printed to the console when found in the log file with Warn level (this can get noisy).

type GrafanaURLProvider added in v1.23.0

type GrafanaURLProvider interface {
	GetGrafanaBaseURL() (string, error)
	GetGrafanaDashboardURL() (string, error)
}

type TestReporter

type TestReporter interface {
	WriteReport(folderLocation string) error
	SendSlackNotification(t *testing.T, slackClient *slack.Client, grafanaUrlProvider GrafanaURLProvider) error
	SetNamespace(namespace string)
}

TestReporter is a general interface for all test reporters

type WarnAboutAllowedMsgs added in v1.28.12

type WarnAboutAllowedMsgs = bool
const (
	WarnAboutAllowedMsgs_Yes WarnAboutAllowedMsgs = true
	WarnAboutAllowedMsgs_No  WarnAboutAllowedMsgs = false
)

Jump to

Keyboard shortcuts

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