Skip to content

package e2etest

import "github.com/cloudboss/unobin/pkg/e2etest"

Package e2etest compiles and runs fixture-based tests for Unobin factories and libraries. Build-heavy cases are skipped by go test -short.

Functions

func RunCompiledCases

func RunCompiledCases(t *testing.T, dir string, opts ...Option)

RunCompiledCases runs compiled-factory cases found under dir.

func RunSourceCases

func RunSourceCases(t *testing.T, dir string, opts ...Option)

RunSourceCases runs source-root cases found under dir.

Types

type AssetBundleCheck

type AssetBundleCheck struct {
    SetCount  int `json:"setCount"`
    BlobCount int `json:"blobCount"`
}

type AssetCacheCheck

type AssetCacheCheck struct {
    Path           string `json:"path"`
    ReferenceCount int    `json:"referenceCount"`
}

type AssetIdentityCheck

type AssetIdentityCheck struct {
    Asset           string `json:"asset"`
    StableEntry     string `json:"stableEntry"`
    ChangePath      string `json:"changePath"`
    ReplacementPath string `json:"replacementPath"`
}

type Command

type Command struct {
    Name            string            `json:"name"`
    Args            []string          `json:"args"`
    Dir             string            `json:"dir"`
    Env             map[string]string `json:"env"`
    Stdout          string            `json:"stdout"`
    Stderr          string            `json:"stderr"`
    Normalize       string            `json:"normalize"`
    ExitCode        int               `json:"exitCode"`
    SkipPin         bool              `json:"skipPin"`
    TamperPlanFiles []string          `json:"tamperPlanFiles"`
}

Command describes one subprocess invocation.

type CommandResult

type CommandResult struct {
    Stdout   string
    Stderr   string
    ExitCode int
}

CommandResult stores the process result for one command.

type CompiledCase

type CompiledCase struct {
    Name                string               `json:"name"`
    Dir                 string               `json:"-"`
    FactoryPath         string               `json:"factoryPath"`
    LibraryPath         string               `json:"libraryPath"`
    Build               bool                 `json:"build"`
    EmptyDirectories    []string             `json:"emptyDirectories"`
    RemoveAfterCompile  []string             `json:"removeAfterCompile"`
    AssetBundle         *AssetBundleCheck    `json:"assetBundle"`
    AssetCache          *AssetCacheCheck     `json:"assetCache"`
    AssetIdentity       *AssetIdentityCheck  `json:"assetIdentity"`
    Commands            []Command            `json:"commands"`
    Files               []FileCheck          `json:"files"`
    FileExclusions      []FileExclusionCheck `json:"fileExclusions"`
    PlanSummaries       []PlanSummaryCheck   `json:"planSummaries"`
    PlanEnvelopes       []PlanEnvelopeCheck  `json:"planEnvelopes"`
    StateEnvelopes      []StateEnvelopeCheck `json:"stateEnvelopes"`
    AbsentFiles         []string             `json:"absentFiles"`
    StateSummary        string               `json:"stateSummary"`
    StateSeed           string               `json:"stateSeed"`
    ExtraStateSnapshots int                  `json:"extraStateSnapshots"`
    StateLocks          []string             `json:"stateLocks"`
    Deterministic       bool                 `json:"deterministic"`
}

CompiledCase describes a compiled-factory e2e case.

func DiscoverCompiledCases

func DiscoverCompiledCases(dir string) ([]CompiledCase, error)

DiscoverCompiledCases reads compiled-factory case.json files under dir.

type FileCheck

type FileCheck struct {
    Path string `json:"path"`
    Want string `json:"want"`
}

FileCheck describes a file compared to a golden.

type FileExclusionCheck

type FileExclusionCheck struct {
    Path string   `json:"path"`
    Text []string `json:"text"`
}

FileExclusionCheck rejects text in a generated text or binary file.

type GoLibrarySource

type GoLibrarySource struct {
    Name          string   `json:"name"`
    Resources     []string `json:"resources"`
    DataSources   []string `json:"dataSources"`
    Configuration bool     `json:"configuration"`
}

type Option

type Option func(*config)

Option configures e2e case execution.

func WithEnv

func WithEnv(env map[string]string) Option

WithEnv adds environment variables to case commands, including automatic pinning. Variables declared by an individual command take precedence.

func WithGoModule

func WithGoModule(modulePath, path string) Option

WithGoModule replaces a library module with a local directory when compiling cases.

func WithSourceDirectory

func WithSourceDirectory(path, source string) Option

WithSourceDirectory copies a directory into source-case workspaces if absent.

func WithUnobinDir

func WithUnobinDir(path string) Option

WithUnobinDir selects a local Unobin checkout or module directory.

func WithUnobinExecutable

func WithUnobinExecutable(path string) Option

WithUnobinExecutable supplies the CLI used by source cases that run a process.

type PlanEnvelopeCheck

type PlanEnvelopeCheck struct {
    Path string `json:"path"`
    Want string `json:"want"`
}

PlanEnvelopeCheck describes a plan envelope compared to a golden.

type PlanSummaryCheck

type PlanSummaryCheck struct {
    Path          string `json:"path"`
    Want          string `json:"want"`
    IncludeInputs bool   `json:"includeInputs"`
}

PlanSummaryCheck describes a plan file decoded and compared to a golden.

type RemoteSource

type RemoteSource struct {
    Key            string `json:"key"`
    Path           string `json:"path"`
    Commit         string `json:"commit"`
    ProjectPath    string `json:"projectPath"`
    ProjectSubdir  string `json:"projectSubdir"`
    PackageSubdir  string `json:"packageSubdir"`
    SourcePath     bool   `json:"sourcePath"`
    ModuleRootPath string `json:"moduleRootPath"`
    ModulePath     string `json:"modulePath"`
    GoImportPath   string `json:"goImportPath"`
}

RemoteSource describes a fake remote repository used by source-root cases.

type SourceCase

type SourceCase struct {
    Name           string               `json:"name"`
    Dir            string               `json:"-"`
    RootPath       string               `json:"rootPath"`
    Executor       string               `json:"executor"`
    CLIVersion     string               `json:"cliVersion"`
    Build          bool                 `json:"build"`
    Remotes        []RemoteSource       `json:"remotes"`
    Tags           map[string][]string  `json:"tags"`
    GoLibrary      *GoLibrarySource     `json:"goLibrary"`
    Commands       []Command            `json:"commands"`
    Files          []FileCheck          `json:"files"`
    FileExclusions []FileExclusionCheck `json:"fileExclusions"`
    AbsentFiles    []string             `json:"absentFiles"`
}

SourceCase describes a source-root CLI e2e case.

func DiscoverSourceCases

func DiscoverSourceCases(dir string) ([]SourceCase, error)

DiscoverSourceCases reads source-root case.json files under dir.

type StateEnvelopeCheck

type StateEnvelopeCheck struct {
    Stack string `json:"stack"`
    Want  string `json:"want"`
}

StateEnvelopeCheck describes a current state envelope compared to a golden.