infratests

package
v0.0.0-...-5957262 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package infratests This file provides abstractions that simplify the process of integration-testing terraform templates. The goal is to minimize the boiler plate code required to effectively test terraform templates in order to reduce the effort required to write robust template integration-tests.

Package infratests this file provides a model for the JSON representation of a terraform plan. It describes a minimal set of metadata produced by the plan and can be expanded to support other attributes if needed

Package infratests This file provides abstractions that simplify the process of unit-testing terraform templates. The goal is to minimize the boiler plate code required to effectively test terraform templates in order to reduce the effort required to write robust template unit-tests.

Package infratests This file provides validation utilities that can be used by the core testing constructs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunIntegrationTests

func RunIntegrationTests(fixture *IntegrationTestFixture)

RunIntegrationTests Executes terraform lifecycle events and verifies the correctness of the resulting resources. The following actions are coordinated:

  • Run `terraform init`
  • Run `terraform output`
  • Validate outputs
  • Run user-supplied validation of outputs

func RunUnitTests

func RunUnitTests(fixture *UnitTestFixture)

RunUnitTests Executes terraform lifecycle events and verifies the correctness of the resulting terraform. The following actions are coordinated:

  • Run `terraform init`
  • Create new terraform workspace. This helps prevent accidentally deleting resources
  • Run `terraform plan`
  • Validate terraform plan file.

Types

type IntegrationTestFixture

type IntegrationTestFixture struct {
	GoTest                *testing.T                  // Go test harness
	TfOptions             *terraform.Options          // Terraform options
	ExpectedTfOutputCount int                         // Expected # of resources that Terraform should create
	ExpectedTfOutput      TerraformOutput             // Expected Terraform Output
	TfOutputAssertions    []TerraformOutputValidation // user-defined plan assertions
}

IntegrationTestFixture Holds metadata required to execute an integration test against a test against a terraform template

type ResourceDescription

type ResourceDescription map[string]map[string]interface{}

ResourceDescription Identifies mappings between resources and attributes

type TerraformOutput

type TerraformOutput map[string]interface{}

TerraformOutput Models terraform output key values

type TerraformOutputValidation

type TerraformOutputValidation func(goTest *testing.T, output TerraformOutput)

TerraformOutputValidation A function that can validate terraform output

type TerraformPlan

type TerraformPlan struct {
	ResourceChanges []struct {
		Address string `json:"address"`
		Change  struct {
			Actions []string               `json:"actions"`
			After   map[string]interface{} `json:"after"`
		} `json:"change"`
	} `json:"resource_changes"`
}

TerraformPlan a JSON schema for the output of `terraform plan <planfile>`

type TerraformPlanValidation

type TerraformPlanValidation func(goTest *testing.T, plan TerraformPlan)

TerraformPlanValidation A function that can run an assertion over a terraform plan

type UnitTestFixture

type UnitTestFixture struct {
	GoTest                *testing.T         // Go test harness
	TfOptions             *terraform.Options // Terraform options
	Workspace             string
	ExpectedResourceCount int // Expected # of resources that Terraform should create
	// map of maps specifying resource <--> attribute <--> attribute value mappings
	ExpectedResourceAttributeValues ResourceDescription
	PlanAssertions                  []TerraformPlanValidation // user-defined plan assertions
}

UnitTestFixture Holds metadata required to execute a unit test against a test against a terraform template

Jump to

Keyboard shortcuts

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