Documentation
¶
Index ¶
- func CreateOrgProjectAndAssetAssetVersion(db shared.DB) (models.Org, models.Project, models.Asset, models.AssetVersion)
- func InitDatabaseContainer(initDBSQLPath string) (shared.DB, *pgxpool.Pool, func())
- func InitRawDatabaseContainer(initDBSQLPath string) (*pgxpool.Pool, func())
- func NewContext(r *http.Request, w http.ResponseWriter) shared.Context
- func NewUserSession(t testing.TB, userID string) *mocks.AuthSession
- func WithTestApp(t *testing.T, sqlInitFile string, testFn func(*TestFixture))
- func WithTestAppOptions(t *testing.T, sqlInitFile string, options TestAppOptions, ...)
- type QueryCounter
- func (q *QueryCounter) Calls() int64
- func (q *QueryCounter) Duration() time.Duration
- func (q *QueryCounter) Initialize(db *gorm.DB) error
- func (q *QueryCounter) Name() string
- func (q *QueryCounter) Report(topN, iterations int) []string
- func (q *QueryCounter) Reset()
- func (q *QueryCounter) Rows() int64
- func (q *QueryCounter) TopStats(n int) []QueryStat
- type QueryStat
- type TestApp
- type TestAppOptions
- type TestFixture
- func (f *TestFixture) CreateAsset(projectID uuid.UUID, name string) models.Asset
- func (f *TestFixture) CreateAssetVersion(assetID uuid.UUID, name string, isDefault bool) models.AssetVersion
- func (f *TestFixture) CreateDaemonRunner() *daemons.DaemonRunner
- func (f *TestFixture) CreateOrg(name string) models.Org
- func (f *TestFixture) CreateOrgProjectAssetAndVersion() (models.Org, models.Project, models.Asset, models.AssetVersion)
- func (f *TestFixture) CreateProject(orgID uuid.UUID, name string) models.Project
- type TestGitlabClientFactory
- func (f TestGitlabClientFactory) FromAccessToken(accessToken string, baseURL string) (shared.GitlabClientFacade, error)
- func (f TestGitlabClientFactory) FromIntegration(integration models.GitLabIntegration) (shared.GitlabClientFacade, error)
- func (f TestGitlabClientFactory) FromIntegrationUUID(_ context.Context, id uuid.UUID) (shared.GitlabClientFacade, error)
- func (f TestGitlabClientFactory) FromOauth2Token(_ context.Context, token models.GitLabOauth2Token, enableClientCache bool) (shared.GitlabClientFacade, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitDatabaseContainer ¶
func NewContext ¶
func NewUserSession ¶ added in v1.11.0
func NewUserSession(t testing.TB, userID string) *mocks.AuthSession
NewUserSession returns a fully-stubbed user-owned shared.AuthSession mock. Every AuthSession method is stubbed with .Maybe() so callers don't need to know in advance which subset the code path under test will invoke — this is the single place to update when the AuthSession interface changes, instead of every test hand-rolling its own mocks.NewAuthSession(t) + .On(...) chain. Call .On(...) on the returned mock afterwards to override a default.
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 QueryCounter ¶ added in v1.12.0
type QueryCounter struct {
// contains filtered or unexported fields
}
QueryCounter is a GORM plugin that counts every statement issued through a *gorm.DB, so benchmarks can report queries/op and spot N+1 patterns.
It is intended for tests/benchmarks only: it keeps one entry per distinct normalized statement in memory.
func NewQueryCounter ¶ added in v1.12.0
func NewQueryCounter() *QueryCounter
func (*QueryCounter) Calls ¶ added in v1.12.0
func (q *QueryCounter) Calls() int64
func (*QueryCounter) Duration ¶ added in v1.12.0
func (q *QueryCounter) Duration() time.Duration
func (*QueryCounter) Initialize ¶ added in v1.12.0
func (q *QueryCounter) Initialize(db *gorm.DB) error
Initialize registers the counting callbacks on every GORM processor.
func (*QueryCounter) Name ¶ added in v1.12.0
func (q *QueryCounter) Name() string
func (*QueryCounter) Report ¶ added in v1.12.0
func (q *QueryCounter) Report(topN, iterations int) []string
Report renders a compact, line-oriented summary. iterations scales the per-call numbers down to "per benchmark iteration".
func (*QueryCounter) Reset ¶ added in v1.12.0
func (q *QueryCounter) Reset()
Reset clears all collected data. Call it right before the measured section.
func (*QueryCounter) Rows ¶ added in v1.12.0
func (q *QueryCounter) Rows() int64
func (*QueryCounter) TopStats ¶ added in v1.12.0
func (q *QueryCounter) TopStats(n int) []QueryStat
TopStats returns the n statements with the most calls, descending.
type QueryStat ¶ added in v1.12.0
QueryStat aggregates all executions of a single normalized statement.
type TestApp ¶
type TestApp struct {
fx.In
// Core infrastructure
DB shared.DB
Broker shared.PubSubBroker
// 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
MaliciousPackageChecker shared.MaliciousPackageChecker
// 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
VEXRuleController *controllers.VEXRuleController
ExternalReferenceController *controllers.ExternalReferenceController
StatisticsController *controllers.StatisticsController
VulnDBController *controllers.VulnDBController
// 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
VexRuleRepository shared.VEXRuleRepository
VexRuleRecommendationRepository shared.VEXRuleRecommendationRepository
TrustedEntityRepository shared.TrustedEntityRepository
ExternalReferenceRepository shared.ExternalReferenceRepository
UpstreamVEXRuleRepository shared.UpstreamVEXRuleRepository
// Access Control
RBACProvider shared.RBACProvider
// Integrations
GitlabIntegration *gitlabint.GitlabIntegration
IntegrationAggregate shared.IntegrationAggregate
VulnDBService shared.VulnDBService
// Daemons
DaemonRunner shared.DaemonRunner
FixedVersionResolver shared.FixedVersionResolver
}
TestApp provides access to all services and controllers via FX
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 shared.PubSubBroker
}
TestAppOptions configures the test application
type TestFixture ¶
type TestFixture struct {
T testing.TB
App *TestApp
DB shared.DB
// pool is the underlying pgx connection pool
// its used by the database broker and other components
Pool *pgxpool.Pool
}
TestFixture provides a complete test environment with database and FX app
func NewTestFixture ¶
func NewTestFixture(t testing.TB, sqlInitFile string, options *TestAppOptions) *TestFixture
NewTestFixture creates a complete test environment with database container and FX app
func (*TestFixture) CreateAsset ¶
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 ¶
CreateProject creates a test project
type TestGitlabClientFactory ¶
type TestGitlabClientFactory struct {
*mocks.GitlabClientFacade
}
func NewTestClientFactory ¶
func NewTestClientFactory(t *testing.T) (TestGitlabClientFactory, *mocks.GitlabClientFacade)
func (TestGitlabClientFactory) FromAccessToken ¶
func (f TestGitlabClientFactory) FromAccessToken(accessToken string, baseURL string) (shared.GitlabClientFacade, error)
func (TestGitlabClientFactory) FromIntegration ¶
func (f TestGitlabClientFactory) FromIntegration(integration models.GitLabIntegration) (shared.GitlabClientFacade, error)
func (TestGitlabClientFactory) FromIntegrationUUID ¶
func (f TestGitlabClientFactory) FromIntegrationUUID(_ context.Context, id uuid.UUID) (shared.GitlabClientFacade, error)
func (TestGitlabClientFactory) FromOauth2Token ¶
func (f TestGitlabClientFactory) FromOauth2Token(_ context.Context, token models.GitLabOauth2Token, enableClientCache bool) (shared.GitlabClientFacade, error)