testutil

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testutil provides utility functions for tests.

Index

Constants

View Source
const Redacted = "REDACTED"

Redacted marks an intentionally removed field.

Variables

View Source
var SilentLogger = zerolog.Nop()

SilentLogger discards all inputs.

Functions

func ExtractFixtureArchive

func ExtractFixtureArchive(t *testing.T, archivePath string) string

ExtractFixtureArchive extracts a test fixture's TAR archive to a temporary directory and returns its path.

func RequireMatchingPropertyToBeRedacted

func RequireMatchingPropertyToBeRedacted(t *testing.T, properties []cdx.Property, name, valueRegex string)

RequireMatchingPropertyToBeRedacted ensures that a given property is present and its value matched the provided regex.

If a property matches, its value is then replaced by the string "REDACTED". This is intended to be used for properties that hold dynamic values that are expected to differ from system to system. Only use if absolutely necessary!

func RequireMatchingSBOMSnapshot

func RequireMatchingSBOMSnapshot(t *testing.T, snapShooter *cupaloy.Config, bom *cdx.BOM, fileFormat cdx.BOMFileFormat)

RequireMatchingSBOMSnapshot encodes a BOM and compares it to the snapshot of a test case.

func RequireStdlibComponentToBeRedacted

func RequireStdlibComponentToBeRedacted(t *testing.T, bom *cdx.BOM, expectPackages, expectFiles bool)

RequireStdlibComponentToBeRedacted ensures that a stdlib component is present and redacts its version.

Version will be redacted from packages as well, if applicable. If files are expected, their correlating components will be removed and replaced by an empty slice.

func RequireValidSBOM

func RequireValidSBOM(t *testing.T, bom *cdx.BOM, fileFormat cdx.BOMFileFormat)

RequireValidSBOM encodes the BOM and validates it using the CycloneDX CLI.

func SkipIfShort

func SkipIfShort(t *testing.T)

SkipIfShort skips the test if `go test` was launched using the -short flag.

Types

This section is empty.

Jump to

Keyboard shortcuts

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