testreporters

package
v1.99.3 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 18 Imported by: 6

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

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

func FindAllLogFilesToScan

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

func MkdirIfNotExists(dirName string) error

creates a directory if it doesn't already exist

func ScanLogLine

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

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

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

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

func SlackNotifyBlocks

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

SlackNotifyBlocks creates a slack payload and writes into the specified json

func UploadSlackFile

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

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

func VerifyLogFile

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

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

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

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

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

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