Documentation
¶
Overview ¶
Package testing provides integration test helpers for Deployah scenarios.
Scenario directories under scenarios/ hold sample specs, environment files, and expected Kubernetes output. DiscoverScenarios finds them automatically; IntegrationTestSuite loads a spec, generates a chart, renders templates, and compares results to golden files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var TestScenariosDir = getTestScenariosDir()
TestScenariosDir is the directory containing integration test scenarios.
Functions ¶
func RunPlanScenarioTest ¶ added in v0.4.0
func RunPlanScenarioTest(t *testing.T, scenario PlanTestScenario)
RunPlanScenarioTest resolves scenario's previous/current manifest pair, computes the diff through the real plan engine, and checks the result against plan-config.yaml (and, when present, golden.txt/golden.json).
Types ¶
type IntegrationTestSuite ¶
type IntegrationTestSuite struct {
// ScenariosDir is the root directory of test scenarios.
ScenariosDir string
// OutputDir is the temporary workspace for a test run.
OutputDir string
}
IntegrationTestSuite runs scenario-based chart and manifest tests.
func NewIntegrationTestSuite ¶
func NewIntegrationTestSuite(t *testing.T) *IntegrationTestSuite
NewIntegrationTestSuite creates a suite rooted at TestScenariosDir.
func (*IntegrationTestSuite) RunScenarioTest ¶
func (suite *IntegrationTestSuite) RunScenarioTest(t *testing.T, scenario TestScenario)
RunScenarioTest executes a test for a specific scenario
type PlanConfig ¶ added in v0.4.0
type PlanConfig struct {
// FreshInstall selects an empty previous manifest instead of resolving
// one from before.yaml or previous.yaml, for the fresh-install case
// where neither file is expected to exist.
FreshInstall bool `yaml:"freshInstall"`
// Changes lists every expected change, in the exact order
// [plan.ComputeDiff] returns them (sorted by Kind, then Name).
Changes []PlanConfigChange `yaml:"changes"`
// Summary is the expected change tally.
Summary PlanConfigSummary `yaml:"summary"`
// HooksChanged asserts [plan.Plan.HooksChanged]. Always false in this
// scenario suite today: the embedded chart defines no hooks, so this
// only documents the plumbing for when one is added.
HooksChanged bool `yaml:"hooksChanged"`
// Masked lists field paths (as they appear in a Changes[].Fields[]
// entry's Path) that [plan.ApplyMasking] must flag as masked. Every
// masked path [RunPlanScenarioTest] finds in the computed plan must
// appear here, and vice versa.
Masked []string `yaml:"masked"`
// Warning is documentary only: this offline harness has no live/faked
// release store to compute a real warning from ([plan.LastSuccessfulRelease]
// is covered separately in history_test.go), so the test runner just
// sets Header.Warning to this value before checking it.
Warning string `yaml:"warning"`
}
PlanConfig is the structural expectation a scenario author writes by hand in plan-config.yaml: what plan.ComputeDiff must produce for this scenario's before/after pair, independent of how the text or JSON renderers format it.
type PlanConfigChange ¶ added in v0.4.0
type PlanConfigChange struct {
Action string `yaml:"action"`
Kind string `yaml:"kind"`
Name string `yaml:"name"`
Fields []PlanConfigField `yaml:"fields"`
}
PlanConfigChange is one expected entry in PlanConfig.Changes.
type PlanConfigField ¶ added in v0.4.0
type PlanConfigField struct {
Path string `yaml:"path"`
Old string `yaml:"old"`
New string `yaml:"new"`
}
PlanConfigField is one expected field-level difference within a PlanConfigChange. Old is empty for an added field; New is empty for a removed field, mirroring plan.FieldDiff.
type PlanConfigSummary ¶ added in v0.4.0
type PlanConfigSummary struct {
Add int `yaml:"add"`
Change int `yaml:"change"`
Destroy int `yaml:"destroy"`
}
PlanConfigSummary is the expected plan.Summary.
type PlanTestScenario ¶ added in v0.4.0
type PlanTestScenario struct {
// Name is the scenario directory name (e.g. "plan-image-bump").
Name string
// Dir is the scenario's absolute directory path.
Dir string
}
PlanTestScenario describes one scenarios/plan-* directory: a before/after manifest pair (however each side is sourced) that RunPlanScenarioTest diffs through the real plan.ComputeDiff engine and checks against plan-config.yaml.
func DiscoverPlanScenarios ¶ added in v0.4.0
func DiscoverPlanScenarios(scenariosDir string) ([]PlanTestScenario, error)
DiscoverPlanScenarios finds every scenarios/plan-* directory with a plan-config.yaml. Unlike DiscoverScenarios, deployah.yaml is optional: RunPlanScenarioTest falls back to a raw current.yaml for kinds the spec/chart pipeline can't produce (e.g. a Secret).
type TestScenario ¶
type TestScenario struct {
// Name is the scenario directory name.
Name string
// ScenarioDir is the relative path under TestScenariosDir.
ScenarioDir string
// ManifestFile is the manifest filename within ScenarioDir.
ManifestFile string
// Environment selects the manifest environment for chart generation.
Environment string
// EnvFiles lists dotenv files to copy into the test workspace.
EnvFiles []string
// PlatformFile is the platform filename within ScenarioDir when present.
PlatformFile string
// ExpectedDir is the golden output directory, relative to TestScenariosDir.
ExpectedDir string
// ExpectError requires manifest loading or resolution to fail.
ExpectError bool
// ExpectedErrors requires specific substrings in the load/resolve error message.
ExpectedErrors []string
}
TestScenario describes one integration test case under scenarios/.
func DiscoverScenarios ¶
func DiscoverScenarios(scenariosDir string) ([]TestScenario, error)
DiscoverScenarios discovers test scenarios from the directory structure.