provisioneracc

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package provisioneracc creates a framework for provisioner acceptance testing. For builder acceptance testing, use the top level tooling in the acctest package.

Index

Constants

This section is empty.

Variables

View Source
var AmasonEBSBuilderFixtureLinux = &BuilderFixture{
	Name:         "Amazon-ebs Linux builder",
	TemplatePath: "amazon-ebs/amazon-ebs.txt",
	GuestOS:      "linux",
	HostOS:       "any",
	Teardown: func() error {

		return nil
	},
}

AmasonEBSBuilderFixtureLinux points to a build stub of a simple amazon-ebs build running on a linux operating system.

View Source
var AmasonEBSBuilderFixtureWindows = &BuilderFixture{
	Name:         "Amazon-ebs Windows builder",
	TemplatePath: "amazon-ebs/amazon-ebs_windows.txt",
	GuestOS:      "windows",
	HostOS:       "any",
	Teardown: func() error {

		return nil
	},
}

AmasonEBSBuilderFixtureWindows points to a build stub of a simple amazon-ebs build running on a Windows operating system.

Mapping of all builder fixtures defined for a given builder type.

View Source
var VirtualboxBuilderFixtureLinux = &BuilderFixture{
	Name:         "Virtualbox Windows builder",
	TemplatePath: "virtualbox/virtualbox-iso.txt",
	GuestOS:      "linux",
	HostOS:       "any",
	Teardown: func() error {
		testutils.CleanupFiles("virtualbox-iso-packer-acc-test")
		testutils.CleanupFiles("packer_cache")
		return nil
	},
}

VirtualboxBuilderFixtureLinux points to a build stub of a simple amazon-ebs build running on a linux operating system.

Functions

func LoadBuilderFragment

func LoadBuilderFragment(templateFragmentPath string) (string, error)

func RunProvisionerAccTest

func RunProvisionerAccTest(testCase *ProvisionerTestCase, t *testing.T)

func TestProvisionersAgainstBuilders

func TestProvisionersAgainstBuilders(testCase *ProvisionerTestCase, t *testing.T)

Types

type BuilderAcceptance

type BuilderAcceptance interface {
	// GetConfigs provides a mapping of guest OS architecture to builder
	// template fragment.
	// The builder template fragment must be a json-formatted string containing
	// the builder definition but no other portions of a packer template. For
	// example:
	//
	// “`json
	// {
	// 	"type": "null",
	// 	"communicator", "none"
	// }
	//“`
	//
	// is a valid entry for "template" here, but the complete Packer template:
	//
	// “`json
	// {
	// 	"builders": [
	// 		"type": "null",
	// 		"communicator": "none"
	// 	]
	// }
	// “`
	//
	// is invalid as input.
	//
	// Valid keys for the map are "linux" and "windows". These keys will be used
	// to determine whether a given builder template is compatible with a given
	// provisioner template.
	GetConfigs() (map[string]string, error)
	// GetBuilderStore() returns a MapOfBuilder that contains the actual builder
	// struct definition being used for this test.
	GetBuilderStore() packersdk.MapOfBuilder
	// CleanUp cleans up any side-effects of the builder not already cleaned up
	// by the builderT framework.
	CleanUp() error
}

BuilderAcceptance is specialized tooling implemented by individual builders. To add your builder to the provisioner testing framework, create a struct that implements this interface, add it to the BuildersAccTest map below. TODO add this interface to the plugin server so that Packer can request it From the plugin rather than importing it here.

type BuilderFixture

type BuilderFixture struct {
	// Name is the name of the builder fixture.
	// Be simple and descriptive.
	Name string
	// Setup creates necessary extra test fixtures, and renders their values
	// into the BuilderFixture.Template.
	Setup func()
	// Template is the path to a builder template fragment.
	// The builder template fragment must be a json-formatted file containing
	// the builder definition but no other portions of a packer template. For
	// example:
	//
	// “`json
	// {
	// 	"type": "null",
	// 	"communicator", "none"
	// }
	//“`
	//
	// is a valid entry for "template" here, but the complete Packer template:
	//
	// “`json
	// {
	// 	"builders": [
	// 		"type": "null",
	// 		"communicator": "none"
	// 	]
	// }
	// “`
	//
	// is invalid as input.
	//
	// Only provide one builder template fragment per file.
	TemplatePath string

	// GuestOS says what guest os type the builder template fragment creates.
	// Valid values are "windows", "linux" or "darwin" guests.
	GuestOS string

	// HostOS says what host os type the builder is capable of running on.
	// Valid values are "any", windows", or "posix". If you set "posix", then
	// this builder can run on a "linux" or "darwin" platform. If you set
	// "any", then this builder can be used on any platform.
	HostOS string

	Teardown builderT.TestTeardownFunc
}

BuilderFixtures are basic builder test configurations and metadata used in provisioner acceptance testing. These are frameworks to be used by provisioner tests, not tests in and of themselves. BuilderFixtures should generally be simple and not contain excessive or complex configurations. Instantiations of this struct are stored in the builders.go file in this module.

type ProvisionerTestCase

type ProvisionerTestCase struct {
	// Check is called after this step is executed in order to test that
	// the step executed successfully. If this is not set, then the next
	// step will be called
	Check func(*exec.Cmd, string) error
	// IsCompatible checks whether a provisioner is able to run against a
	// given builder type and guest operating system, and returns a boolean.
	// if it returns true, the test combination is okay to run. If false, the
	// test combination is not okay to run.
	IsCompatible func(builderType string, BuilderGuestOS string) bool
	// Name is the name of the test case. Be simple but unique and descriptive.
	Name string
	// Setup, if non-nil, will be called once before the test case
	// runs. This can be used for some setup like setting environment
	// variables, or for validation prior to the
	// test running. For example, you can use this to make sure certain
	// binaries are installed, or text fixtures are in place.
	Setup func() error
	// Teardown will be called before the test case is over regardless
	// of if the test succeeded or failed. This should return an error
	// in the case that the test can't guarantee all resources were
	// properly cleaned up.
	Teardown builderT.TestTeardownFunc
	// Template is the provisioner template to use.
	// The provisioner template fragment must be a json-formatted string
	// containing the provisioner definition but no other portions of a packer
	// template. For
	// example:
	//
	// “`json
	// {
	// 	"type": "shell-local",
	// 	"inline", ["echo hello world"]
	// }
	//“`
	//
	// is a valid entry for "template" here, but the complete Packer template:
	//
	// “`json
	// {
	// 	"provisioners": [
	// 		{
	// 			"type": "shell-local",
	// 			"inline", ["echo hello world"]
	// 		}
	// 	]
	// }
	// “`
	//
	// is invalid as input.
	//
	// You may provide multiple provisioners in the same template. For example:
	// “`json
	// {
	// 	"type": "shell-local",
	// 	"inline", ["echo hello world"]
	// },
	// {
	// 	"type": "shell-local",
	// 	"inline", ["echo hello world 2"]
	// }
	// “`
	Template string
	// Type is the type of provisioner.
	Type string
}

ProvisionerTestCase is a single set of tests to run for a provisioner. A ProvisionerTestCase should generally map 1:1 to each test method for your acceptance tests.

Jump to

Keyboard shortcuts

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