tests

package
v1.0.0-rc.12 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOrgProjectAndAssetAssetVersion

func CreateOrgProjectAndAssetAssetVersion(db shared.DB) (models.Org, models.Project, models.Asset, models.AssetVersion)

func InitDatabaseContainer

func InitDatabaseContainer(initDBSQLPath string) (shared.DB, func())

func InitSQLDatabaseContainer

func InitSQLDatabaseContainer(initDBSQLPath string) (string, string, string, string, string, func())

InitSQLDatabaseContainer initializes a test database container and returns the underlying SQL DB and connection string instead of GORM DB. Useful for components that need direct SQL access.

func NewContext

func NewContext(r *http.Request, w http.ResponseWriter) shared.Context

func ReaderFromAny

func ReaderFromAny(v any) io.Reader

func WithTestApp

func WithTestApp(t *testing.T, sqlInitFile string, testFn func(*TestFixture))

WithTestApp provides a callback-based pattern for tests

func WithTestAppOptions

func WithTestAppOptions(t *testing.T, sqlInitFile string, options TestAppOptions, testFn func(*TestFixture))

Types

type SessionMock

type SessionMock struct {
	UserID string
	Scopes []string
}

func NewSessionMock

func NewSessionMock(userID string) SessionMock

func (SessionMock) GetScopes

func (s SessionMock) GetScopes() []string

func (SessionMock) GetUserID

func (s SessionMock) GetUserID() string

type TestApp

type TestApp struct {
	fx.In

	// Core infrastructure
	DB     shared.DB
	Broker database.Broker

	// Services
	ConfigService            shared.ConfigService
	LicenseRiskService       shared.LicenseRiskService
	StatisticsService        shared.StatisticsService
	ComponentService         shared.ComponentService
	FirstPartyVulnService    shared.FirstPartyVulnService
	DependencyVulnService    shared.DependencyVulnService
	ArtifactService          shared.ArtifactService
	AssetVersionService      shared.AssetVersionService
	AssetService             shared.AssetService
	ProjectService           shared.ProjectService
	OrgService               shared.OrgService
	ScanService              shared.ScanService
	CSAFService              shared.CSAFService
	ReleaseService           shared.ReleaseService
	OpenSourceInsightService shared.OpenSourceInsightService

	// Controllers
	AssetController          *controllers.AssetController
	AssetVersionController   *controllers.AssetVersionController
	ScanController           *controllers.ScanController
	ProjectController        *controllers.ProjectController
	OrgController            *controllers.OrgController
	DependencyVulnController *controllers.DependencyVulnController
	FirstPartyVulnController *controllers.FirstPartyVulnController
	ComponentController      *controllers.ComponentController
	ArtifactController       *controllers.ArtifactController
	CSAFController           *controllers.CSAFController

	// Repositories
	AssetRepository             shared.AssetRepository
	AssetVersionRepository      shared.AssetVersionRepository
	ComponentRepository         shared.ComponentRepository
	DependencyVulnRepository    shared.DependencyVulnRepository
	FirstPartyVulnRepository    shared.FirstPartyVulnRepository
	CveRepository               shared.CveRepository
	CweRepository               shared.CweRepository
	ExploitRepository           shared.ExploitRepository
	AffectedComponentRepository shared.AffectedComponentRepository
	ProjectRepository           shared.ProjectRepository
	OrgRepository               shared.OrganizationRepository
	ArtifactRepository          shared.ArtifactRepository
	VulnEventRepository         shared.VulnEventRepository
	ComponentProjectRepository  shared.ComponentProjectRepository
	StatisticsRepository        shared.StatisticsRepository
	LicenseRiskRepository       shared.LicenseRiskRepository
	GitLabOauth2TokenRepository shared.GitLabOauth2TokenRepository
	GitlabIntegrationRepository shared.GitlabIntegrationRepository
	ExternalUserRepository      shared.ExternalUserRepository
	AggregatedVulnRepository    shared.VulnRepository

	// Access Control
	RBACProvider shared.RBACProvider

	// Integrations
	GitlabIntegration    *gitlabint.GitlabIntegration
	IntegrationAggregate shared.IntegrationAggregate
}

TestApp provides access to all services and controllers via FX

func NewTestApp

func NewTestApp(t *testing.T, db shared.DB, opts *TestAppOptions) (*TestApp, *fxtest.App, error)

NewTestApp creates a test application with all dependencies wired via FX It uses the same FX modules as production for consistency

func NewTestAppWithT

func NewTestAppWithT(t *testing.T, db shared.DB, opts *TestAppOptions) (*TestApp, *fxtest.App)

NewTestAppWithT creates a test application tied to a testing.T It automatically stops the app when the test completes

type TestAppOptions

type TestAppOptions struct {
	// Additional FX options to include
	ExtraOptions []fx.Option
	// Whether to suppress FX logging
	SuppressLogs bool
	// Custom broker (if nil, a default in-memory broker will be provided)
	Broker database.Broker
}

TestAppOptions configures the test application

type TestFixture

type TestFixture struct {
	T   *testing.T
	App *TestApp
	DB  shared.DB
}

TestFixture provides a complete test environment with database and FX app

func NewTestFixture

func NewTestFixture(t *testing.T, sqlInitFile string, options *TestAppOptions) *TestFixture

NewTestFixture creates a complete test environment with database container and FX app

func (*TestFixture) CreateAsset

func (f *TestFixture) CreateAsset(projectID uuid.UUID, name string) models.Asset

CreateAsset creates a test asset

func (*TestFixture) CreateAssetVersion

func (f *TestFixture) CreateAssetVersion(assetID uuid.UUID, name string, isDefault bool) models.AssetVersion

CreateAssetVersion creates a test asset version

func (*TestFixture) CreateDaemonRunner

func (f *TestFixture) CreateDaemonRunner() daemons.DaemonRunner

CreateDaemonRunner creates a DaemonRunner instance with all dependencies from the test app

func (*TestFixture) CreateOrg

func (f *TestFixture) CreateOrg(name string) models.Org

CreateOrg creates a test organization

func (*TestFixture) CreateOrgProjectAssetAndVersion

func (f *TestFixture) CreateOrgProjectAssetAndVersion() (models.Org, models.Project, models.Asset, models.AssetVersion)

CreateOrgProjectAssetAndVersion creates a full test hierarchy using FX services

func (*TestFixture) CreateProject

func (f *TestFixture) CreateProject(orgID uuid.UUID, name string) models.Project

CreateProject creates a test project

type TestGitlabClientFactory

type TestGitlabClientFactory struct {
	*mocks.GitlabClientFacade
}

func (TestGitlabClientFactory) FromAccessToken

func (f TestGitlabClientFactory) FromAccessToken(accessToken string, baseURL string) (shared.GitlabClientFacade, error)

func (TestGitlabClientFactory) FromIntegration

func (TestGitlabClientFactory) FromIntegrationUUID

func (f TestGitlabClientFactory) FromIntegrationUUID(id uuid.UUID) (shared.GitlabClientFacade, error)

func (TestGitlabClientFactory) FromOauth2Token

func (f TestGitlabClientFactory) FromOauth2Token(token models.GitLabOauth2Token, enableClientCache bool) (shared.GitlabClientFacade, error)

Jump to

Keyboard shortcuts

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