testcmd

package
v2.3.7 Latest Latest
Warning

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

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

Documentation

Overview

Package testcmd provides utilities for testing osv-scanner CLI commands.

Index

Constants

This section is empty.

Variables

View Source
var CommandsUnderTest []cmd.CommandBuilder

CommandsUnderTest should be set in TestMain by every cmd package test

Functions

func CopyFileFlagTo added in v2.2.0

func CopyFileFlagTo(t *testing.T, tc Case, flagName string, dir string) string

CopyFileFlagTo creates a copy of the file pointed to by the given flag (if present in the test case arguments) in the given directory, updating all references in the arguments before returning the new path.

Values that include "does_not_exist" are assumed to be for testing when the flag is given the path to a file or directory that does not exist, and so are ignored as if the flag was not given a value at all

func InsertCassette added in v2.3.1

func InsertCassette(t *testing.T) *http.Client

InsertCassette returns an http.Client backed by a recorder.Recorder which will record and (re)play responses from a cassette based on the tests name

func RunAndMatchSnapshots

func RunAndMatchSnapshots(t *testing.T, tc Case)

func RunAndNormalize added in v2.2.0

func RunAndNormalize(t *testing.T, tc Case) (string, string)

func SetupGitFixtures added in v2.2.2

func SetupGitFixtures() (func(), error)

func WithTestNameHeader added in v2.3.1

func WithTestNameHeader(t *testing.T, client http.Client) *http.Client

WithTestNameHeader wraps the given http.Client with an http.RoundTripper that adds a custom header to every request with the name of the test being run

Types

type Case

type Case struct {
	Name string
	Args []string
	Exit int

	// ReplaceRules are only used for JSON output
	ReplaceRules []testutility.JSONReplaceRule

	HTTPClient *http.Client
}

Jump to

Keyboard shortcuts

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