Documentation
¶
Overview ¶
Package testutil implements test setup functionality
Package testutil implements test setup functionality
Index ¶
- func CLIDownloadLockFileCleanUp(t *testing.T, c *config.Config)
- func CreateDummyProgressListener(t *testing.T)
- func EnableSastAndAutoFix(c *config.Config)
- func ExecuteAndCaptureConfig(t *testing.T, c *config.Config, executor CLIExecutor, cmd []string, ...) (capturedOrg interface{}, capturedWorkingDir string)
- func IntegTest(t *testing.T) *config.Config
- func MockAndCaptureWorkflowInvocation(t *testing.T, mockEngine *mocks.MockEngine, workflowID workflow.Identifier, ...) chan WorkflowCapture
- func NewMockIssue(id string, path types.FilePath) *snyk.Issue
- func NewMockIssueWithIgnored(id string, path types.FilePath, ignored bool) *snyk.Issue
- func NewMockIssueWithSeverity(id string, path types.FilePath, severity types.Severity) *snyk.Issue
- func OnlyEnableCode(t *testing.T, c *config.Config)
- func SetUpEngineMock(t *testing.T, c *config.Config) (*mocks.MockEngine, configuration.Configuration)
- func SetupFolderWithOrg(t *testing.T, c *config.Config, orgUUID string) types.FilePath
- func SetupFoldersWithOrgs(t *testing.T, c *config.Config) (folderPath1, folderPath2 types.FilePath, ...)
- func SetupGlobalOrgOnly(t *testing.T, c *config.Config) (folderPath types.FilePath, globalOrg string)
- func SkipLocally(t *testing.T)
- func SmokeTest(t *testing.T, tokenSecretName string) *config.Config
- func UnitTest(t *testing.T) *config.Config
- func UnitTestWithCtx(t *testing.T) (*config.Config, context.Context)
- type CLIExecutor
- type WorkflowCapture
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnableSastAndAutoFix ¶ added in v1.1303.0
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 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
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
NewMockIssueWithIgnored creates a mock issue with a specific ignored status.
func NewMockIssueWithSeverity ¶ added in v1.1303.0
NewMockIssueWithSeverity creates a mock issue with a specific severity.
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
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
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. |