testutil

package
v1.1303.0 Latest Latest
Warning

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

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

Documentation

Overview

Package testutil implements test setup functionality

Package testutil implements test setup functionality

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CLIDownloadLockFileCleanUp

func CLIDownloadLockFileCleanUp(t *testing.T, c *config.Config)

func CreateDummyProgressListener

func CreateDummyProgressListener(t *testing.T)

func EnableSastAndAutoFix added in v1.1303.0

func EnableSastAndAutoFix(c *config.Config)

Enables SAST and AutoFix. Used in tests where scan results are provided by code.getSarifResponseJson2, and so we need enable AutoFix in order for the issues to get enhanced with commands (see code.addIssueActions).

func ExecuteAndCaptureConfig added in v1.1303.0

func ExecuteAndCaptureConfig(t *testing.T, c *config.Config, executor CLIExecutor, cmd []string, workingDir types.FilePath) (capturedOrg interface{}, capturedWorkingDir string)

ExecuteAndCaptureConfig executes a CLI command using the provided executor and captures the organization and working directory from the workflow configuration. This is useful for testing that the correct organization is set based on folder configuration.

func IntegTest

func IntegTest(t *testing.T) *config.Config

func MockAndCaptureWorkflowInvocation added in v1.1303.0

func MockAndCaptureWorkflowInvocation(
	t *testing.T,
	mockEngine *mocks.MockEngine,
	workflowID workflow.Identifier,
	times int,
) chan WorkflowCapture

MockAndCaptureWorkflowInvocation sets up a mock expectation to capture workflow invocations. It returns a channel that will receive the captured input data and config from each invocation. The channel is automatically closed via t.Cleanup().

func NewMockIssue added in v1.1303.0

func NewMockIssue(id string, path types.FilePath) *snyk.Issue

NewMockIssue creates a mock issue with default values for testing. The issue has ProductOpenSource, Medium severity, and a generated key.

func NewMockIssueWithIgnored added in v1.1303.0

func NewMockIssueWithIgnored(id string, path types.FilePath, ignored bool) *snyk.Issue

NewMockIssueWithIgnored creates a mock issue with a specific ignored status.

func NewMockIssueWithSeverity added in v1.1303.0

func NewMockIssueWithSeverity(id string, path types.FilePath, severity types.Severity) *snyk.Issue

NewMockIssueWithSeverity creates a mock issue with a specific severity.

func OnlyEnableCode

func OnlyEnableCode(t *testing.T, c *config.Config)

func SetUpEngineMock

func SetUpEngineMock(t *testing.T, c *config.Config) (*mocks.MockEngine, configuration.Configuration)

SetUpEngineMock creates and configures a mock GAF engine for testing. It sets up common expectations (GetConfiguration, GetLogger) and ensures the mock engine's configuration shares the same storage as the original config, allowing folder configurations to be persisted and read correctly across both objects. The mock engine is automatically set on the provided config.

func SetupFolderWithOrg added in v1.1303.0

func SetupFolderWithOrg(t *testing.T, c *config.Config, orgUUID string) types.FilePath

SetupFolderWithOrg is a helper function for integration tests that sets up a single folder with a specific organization. It returns the folder path, org UUID, and the config.

func SetupFoldersWithOrgs added in v1.1303.0

func SetupFoldersWithOrgs(t *testing.T, c *config.Config) (folderPath1, folderPath2 types.FilePath, globalOrg, folderOrg1, folderOrg2 string)

SetupFoldersWithOrgs is a helper function for integration tests that sets up two folders with different organizations. It returns the folder paths, org UUIDs, and the config. The global org is set to a different value than the folder orgs to test isolation.

func SetupGlobalOrgOnly added in v1.1303.0

func SetupGlobalOrgOnly(t *testing.T, c *config.Config) (folderPath types.FilePath, globalOrg string)

SetupGlobalOrgOnly is a helper function for integration tests that sets up only a global org (no folder-specific org). It returns a test folder path and the global org UUID.

func SkipLocally added in v1.1303.0

func SkipLocally(t *testing.T)

func SmokeTest

func SmokeTest(t *testing.T, tokenSecretName string) *config.Config

TODO: remove useConsistentIgnores once we have fully rolled out the feature

func UnitTest

func UnitTest(t *testing.T) *config.Config

func UnitTestWithCtx added in v1.1303.0

func UnitTestWithCtx(t *testing.T) (*config.Config, context.Context)

Types

type CLIExecutor added in v1.1303.0

type CLIExecutor interface {
	Execute(ctx context.Context, cmd []string, workingDir types.FilePath, env gotenv.Env) (resp []byte, err error)
}

CLIExecutor is a minimal interface for executing CLI commands in tests. This allows the test helper to work with any executor implementation.

type WorkflowCapture added in v1.1303.0

type WorkflowCapture struct {
	Input  []workflow.Data
	Config configuration.Configuration
}

WorkflowCapture holds the input data and config captured from a workflow invocation

Directories

Path Synopsis
Package workspaceutil provides workspace setup utilities for tests.
Package workspaceutil provides workspace setup utilities for tests.

Jump to

Keyboard shortcuts

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