testseed

package
v0.19.821 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

README

testseed

Test fixture utilities for ctl-api integration tests.

Setup

type TestService struct {
    fx.In

    DB     *gorm.DB `name:"psql"`
    Seeder *testseed.Seeder
}

func (s *MyTestSuite) SetupSuite() {
    options := append(
        tests.CtlApiFXOptions(),
        fx.Provide(testseed.New),
        fx.Populate(&s.service),
    )

    s.app = fxtest.New(s.T(), options...)
    s.app.RequireStart()
}

Creating Fixtures

Each entity type has two or three functions:

  • Build* -- creates an in-memory struct with fake defaults (no DB)
  • Create* -- builds and persists to the database (uses account/org from context if set)
  • Ensure* -- creates, persists, and sets the entity's ID in the context (Account and Org only)
Setting up an account and org in SetupTest

EnsureAccount and EnsureOrg return an updated context with the IDs set. Subsequent Create* calls on the seeder will pick up these IDs automatically.

func (s *MyTestSuite) SetupTest() {
    s.ctx = context.Background()
    s.ctx, s.testAcc = s.service.Seeder.EnsureAccount(s.ctx, s.T())
    s.ctx, s.testOrg = s.service.Seeder.EnsureOrg(s.ctx, s.T())
}
Creating entities

Create* methods build a struct with fake defaults and persist it in one step. If the context has an account or org ID (set via Ensure*), those are used instead of generating new ones.

// Create an account (standalone, not added to context)
acct := s.service.Seeder.CreateAccount(s.ctx, s.T())

// Create an org (uses account from context for CreatedByID)
org := s.service.Seeder.CreateOrg(s.ctx, s.T())

// Create an app (uses org and account from context)
testApp := s.service.Seeder.CreateApp(s.ctx, s.T())

// Create an install (uses org and account from context)
install := s.service.Seeder.CreateInstall(s.ctx, s.T())
Building without persisting, then saving manually

Build* functions create in-memory structs with generated IDs and fake defaults. You can override fields and save to the DB yourself.

// Build an app in memory
myApp := testseed.BuildApp()

// Override with the test account and org
myApp.CreatedBy = *s.testAcc
myApp.CreatedByID = s.testAcc.ID
myApp.Org = s.testOrg
myApp.OrgID = s.testOrg.ID

// Persist to the database
res := s.service.DB.WithContext(s.ctx).Create(myApp)
require.NoError(s.T(), res.Error)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAccount

func BuildAccount() *app.Account

BuildAccount creates an app.Account with fake defaults.

func BuildApp

func BuildApp() *app.App

BuildApp creates an app.App with fake defaults.

func BuildAppConfig added in v0.19.807

func BuildAppConfig(appID string) *app.AppConfig

BuildAppConfig creates an app.AppConfig with fake defaults for the given app.

func BuildCompletedUserJourney added in v0.19.800

func BuildCompletedUserJourney() app.UserJourney

BuildCompletedUserJourney creates an app.UserJourney with the default onboarding steps, all marked complete. Override fields directly when you need custom values.

func BuildComponent added in v0.19.807

func BuildComponent(appID string) *app.Component

BuildComponent creates an app.Component with fake defaults for the given app.

func BuildInstall

func BuildInstall(a *app.App) *app.Install

BuildInstall creates an app.Install with fake defaults for the given app. The returned install is in-memory only and does not set config FK fields (those require DB queries — use CreateInstall for a fully-populated install).

func BuildOrg

func BuildOrg() *app.Org

BuildOrg creates an app.Org with fake defaults.

func BuildUserJourney added in v0.19.800

func BuildUserJourney() app.UserJourney

BuildUserJourney creates an app.UserJourney with the default onboarding steps, all marked incomplete. Override fields directly when you need custom values.

Types

type Params

type Params struct {
	fx.In

	DB *gorm.DB `name:"psql"`
}

type Seeder

type Seeder struct {
	// contains filtered or unexported fields
}

func New

func New(params Params) *Seeder

func (*Seeder) CreateAccount

func (s *Seeder) CreateAccount(ctx context.Context, t *testing.T) *app.Account

CreateAccount builds and persists an account to the database.

func (*Seeder) CreateActionWorkflow added in v0.19.807

func (s *Seeder) CreateActionWorkflow(ctx context.Context, t *testing.T, appID string) *app.ActionWorkflow

CreateActionWorkflow persists an ActionWorkflow definition scoped to the given app.

func (*Seeder) CreateActionWorkflowConfig added in v0.19.807

func (s *Seeder) CreateActionWorkflowConfig(ctx context.Context, t *testing.T, appID, appConfigID, actionWorkflowID string) *app.ActionWorkflowConfig

CreateActionWorkflowConfig persists an ActionWorkflowConfig with one manual trigger and one step. Three sequential creates are required: ActionWorkflowConfig -> ActionWorkflowTriggerConfig -> ActionWorkflowStepConfig.

func (*Seeder) CreateApp

func (s *Seeder) CreateApp(ctx context.Context, t *testing.T) *app.App

CreateApp builds and persists an app to the database. Uses org/account from context if available.

func (*Seeder) CreateAppBreakGlassConfig added in v0.19.807

func (s *Seeder) CreateAppBreakGlassConfig(ctx context.Context, t *testing.T, appID, appConfigID string) *app.AppBreakGlassConfig

CreateAppBreakGlassConfig persists an empty AppBreakGlassConfig.

func (*Seeder) CreateAppConfig added in v0.19.807

func (s *Seeder) CreateAppConfig(ctx context.Context, t *testing.T, appID string) *app.AppConfig

CreateAppConfig creates a fully-populated AppConfig mirroring what a real CLI sync produces: all required configs, all optional configs, one component of each type, and one action workflow.

func (*Seeder) CreateAppInputConfig added in v0.19.807

func (s *Seeder) CreateAppInputConfig(ctx context.Context, t *testing.T, appID, appConfigID string) *app.AppInputConfig

CreateAppInputConfig persists an AppInputConfig with one AppInputGroup and one AppInput. Three sequential creates are required due to the FK chain: AppInputConfig -> AppInputGroup -> AppInput.

func (*Seeder) CreateAppPermissionsConfig added in v0.19.807

func (s *Seeder) CreateAppPermissionsConfig(ctx context.Context, t *testing.T, appID, appConfigID string) *app.AppPermissionsConfig

CreateAppPermissionsConfig persists an empty AppPermissionsConfig.

func (*Seeder) CreateAppPoliciesConfig added in v0.19.807

func (s *Seeder) CreateAppPoliciesConfig(ctx context.Context, t *testing.T, appID, appConfigID string) *app.AppPoliciesConfig

CreateAppPoliciesConfig persists an empty AppPoliciesConfig.

func (*Seeder) CreateAppRunnerConfig added in v0.19.807

func (s *Seeder) CreateAppRunnerConfig(ctx context.Context, t *testing.T, appID, appConfigID string) *app.AppRunnerConfig

CreateAppRunnerConfig persists an AppRunnerConfig with type aws.

func (*Seeder) CreateAppSandboxConfig added in v0.19.807

func (s *Seeder) CreateAppSandboxConfig(ctx context.Context, t *testing.T, appID, appConfigID string) *app.AppSandboxConfig

CreateAppSandboxConfig persists an AppSandboxConfig with a nested PublicGitVCSConfig.

func (*Seeder) CreateAppSecretsConfig added in v0.19.807

func (s *Seeder) CreateAppSecretsConfig(ctx context.Context, t *testing.T, appID, appConfigID string) *app.AppSecretsConfig

CreateAppSecretsConfig persists an empty AppSecretsConfig.

func (*Seeder) CreateAppStackConfig added in v0.19.807

func (s *Seeder) CreateAppStackConfig(ctx context.Context, t *testing.T, appID, appConfigID string) *app.AppStackConfig

CreateAppStackConfig persists an AppStackConfig of type aws-cloudformation.

func (*Seeder) CreateBareAppConfig added in v0.19.807

func (s *Seeder) CreateBareAppConfig(ctx context.Context, t *testing.T, appID string) *app.AppConfig

CreateBareAppConfig persists a minimal AppConfig shell for the given app to the database. OrgID and CreatedByID are populated by the BeforeCreate hook from context. Use CreateAppConfig for a fully-populated config.

func (*Seeder) CreateComponent added in v0.19.807

func (s *Seeder) CreateComponent(ctx context.Context, t *testing.T, appID string, componentType app.ComponentType) *app.Component

CreateComponent persists a Component for the given app to the database. OrgID and CreatedByID are populated by the BeforeCreate hook from context. Pass a componentType to set the type column (in production this is done by create-config handlers).

func (*Seeder) CreateComponentBuild added in v0.19.807

func (s *Seeder) CreateComponentBuild(ctx context.Context, t *testing.T, configConnectionID string) *app.ComponentBuild

CreateComponentBuild persists a ComponentBuild linked to the given ComponentConfigConnection.

func (*Seeder) CreateDockerBuildComponentConfigConnection added in v0.19.807

func (s *Seeder) CreateDockerBuildComponentConfigConnection(ctx context.Context, t *testing.T, componentID, appConfigID string) *app.ComponentConfigConnection

CreateDockerBuildComponentConfigConnection persists a ComponentConfigConnection with a DockerBuildComponentConfig.

func (*Seeder) CreateExternalImageComponentConfigConnection added in v0.19.807

func (s *Seeder) CreateExternalImageComponentConfigConnection(ctx context.Context, t *testing.T, componentID, appConfigID string) *app.ComponentConfigConnection

CreateExternalImageComponentConfigConnection persists a ComponentConfigConnection with an ExternalImageComponentConfig.

func (*Seeder) CreateHelmComponentConfigConnection added in v0.19.807

func (s *Seeder) CreateHelmComponentConfigConnection(ctx context.Context, t *testing.T, componentID, appConfigID string) *app.ComponentConfigConnection

CreateHelmComponentConfigConnection persists a ComponentConfigConnection with a HelmComponentConfig.

func (*Seeder) CreateInstall

func (s *Seeder) CreateInstall(ctx context.Context, t *testing.T, a *app.App) *app.Install

CreateInstall builds and persists an install to the database for the given app. Requires that CreateAppConfig has already been called for the app — it queries for the latest AppSandboxConfig, AppRunnerConfig, and AppConfig to set FK fields. Creates associated AWSAccount, InstallSandbox, and InstallStack inline. Uses org/account from context if available.

func (*Seeder) CreateInstallComponent added in v0.19.807

func (s *Seeder) CreateInstallComponent(ctx context.Context, t *testing.T, installID, componentID string) *app.InstallComponent

CreateInstallComponent persists an InstallComponent linking an install to a component. OrgID and CreatedByID are populated by the BeforeCreate hook from context.

func (*Seeder) CreateInstallDeploy added in v0.19.807

func (s *Seeder) CreateInstallDeploy(ctx context.Context, t *testing.T, installComponentID, componentBuildID string) *app.InstallDeploy

CreateInstallDeploy persists an InstallDeploy linked to an InstallComponent and ComponentBuild.

func (*Seeder) CreateInstallInputs added in v0.19.807

func (s *Seeder) CreateInstallInputs(ctx context.Context, t *testing.T, installID, appInputConfigID string, values map[string]*string) *app.InstallInputs

CreateInstallInputs persists an InstallInputs record for the given install.

func (*Seeder) CreateInstallStackVersion added in v0.19.807

func (s *Seeder) CreateInstallStackVersion(ctx context.Context, t *testing.T, installID, installStackID, appConfigID string) *app.InstallStackVersion

CreateInstallStackVersion persists an InstallStackVersion with a generated PhoneHomeID.

func (*Seeder) CreateJobComponentConfigConnection added in v0.19.807

func (s *Seeder) CreateJobComponentConfigConnection(ctx context.Context, t *testing.T, componentID, appConfigID string) *app.ComponentConfigConnection

CreateJobComponentConfigConnection persists a ComponentConfigConnection with a JobComponentConfig.

func (*Seeder) CreateKubernetesManifestComponentConfigConnection added in v0.19.807

func (s *Seeder) CreateKubernetesManifestComponentConfigConnection(ctx context.Context, t *testing.T, componentID, appConfigID string) *app.ComponentConfigConnection

CreateKubernetesManifestComponentConfigConnection persists a ComponentConfigConnection with a KubernetesManifestComponentConfig.

func (*Seeder) CreateOrg

func (s *Seeder) CreateOrg(ctx context.Context, t *testing.T) *app.Org

CreateOrg builds and persists an org to the database. Uses account from context if available for CreatedByID.

func (*Seeder) CreateRunnerJob added in v0.19.807

func (s *Seeder) CreateRunnerJob(ctx context.Context, t *testing.T, ownerID, ownerType string) *app.RunnerJob

CreateRunnerJob persists a RunnerJob with the given polymorphic owner. Creates a LogStream, RunnerGroup, and Runner inline to satisfy FK constraints.

func (*Seeder) CreateTerraformComponentConfigConnection added in v0.19.807

func (s *Seeder) CreateTerraformComponentConfigConnection(ctx context.Context, t *testing.T, componentID, appConfigID string) *app.ComponentConfigConnection

CreateTerraformComponentConfigConnection persists a ComponentConfigConnection with a TerraformModuleComponentConfig.

func (*Seeder) CreateWorkflow added in v0.19.807

func (s *Seeder) CreateWorkflow(ctx context.Context, t *testing.T, installID string, workflowType app.WorkflowType) *app.Workflow

CreateWorkflow persists a Workflow owned by the given install.

func (*Seeder) CreateWorkflowStep added in v0.19.807

func (s *Seeder) CreateWorkflowStep(ctx context.Context, t *testing.T, workflowID string, opts ...WorkflowStepOption) *app.WorkflowStep

CreateWorkflowStep persists a WorkflowStep for the given workflow.

func (*Seeder) CreateWorkflowStepApproval added in v0.19.807

func (s *Seeder) CreateWorkflowStepApproval(ctx context.Context, t *testing.T, stepID string, approvalType app.WorkflowStepApprovalType, contents string) *app.WorkflowStepApproval

CreateWorkflowStepApproval persists a WorkflowStepApproval for the given step.

func (*Seeder) EnsureAccount

func (s *Seeder) EnsureAccount(ctx context.Context, t *testing.T) (context.Context, *app.Account)

EnsureAccount creates a test account and sets its ID in the context via cctx.SetAccountIDContext.

func (*Seeder) EnsureOrg

func (s *Seeder) EnsureOrg(ctx context.Context, t *testing.T) (context.Context, *app.Org)

EnsureOrg creates a test org and sets its ID in the context via cctx.SetOrgIDContext.

type WorkflowStepOption added in v0.19.807

type WorkflowStepOption func(*app.WorkflowStep)

WorkflowStepOption allows overriding defaults when creating a WorkflowStep.

func WithStepRetryable added in v0.19.807

func WithStepRetryable(retryable bool) WorkflowStepOption

func WithStepSignal added in v0.19.807

func WithStepSignal(signal app.Signal) WorkflowStepOption

func WithStepSkippable added in v0.19.807

func WithStepSkippable(skippable bool) WorkflowStepOption

func WithStepStatus added in v0.19.807

func WithStepStatus(status app.CompositeStatus) WorkflowStepOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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