@octopusdeploy/step-test-framework
v1.0.0
Published
Testing framework for Octopus Step Package Steps
Downloads
104
Keywords
Readme
step-test-framework
An opinionated testing frame work for testing Octopus Step Package Steps.
npm i @octopusdeploy/step-test-framework --save-dev
Overview
The Step Test Framework:
- acquires and sets up Terraform
- declares the required Terraform provider for your target (AzureRM, AWS, GCP)
- provides TypeScript types for required Credentials, for example
AzureCredentials
- provides a simple entry point for setting up the test resources which accepts a path to a single TF file, and a credential
- outputs a random resource code that can both be used in the step authors own terraform templates, and within the tests to access and validate resources
- provides a destructor for the environment that can be used to reliably tear it down once tests are complete
- returns all outputs defined in the test module as a single untyped object, ex.
test_module_output: any = {
virtual_network_name: "octotetra"
}
Example
This example deploys a new vnet to Azure. The frame
|--
- test-module.tf
- test.spec.ts
test-module.tf
variable "resource_code" {
type = string
}
variable "resource_group_name" {
type = string
}
variable "resource_group_location" {
type = string
}
resource "azurerm_virtual_network" "example" {
name = "octo${var.resource_code}"
resource_group_name = var.resource_group_name
location = var.resource_group_location
address_space = ["10.254.0.0/16"]
}
output "virtual_network_name" {
value = azurerm_virtual_network.example.name
}
test.spec.ts
const credentials: AzureCredentials = {
client_id: clientId,
subscription_id: subscriptionId,
tenant_id: tenantId,
client_secret: password,
};
const result = await setupAzureEnvironment(join(__dirname, "blob-storage.tf"), credentials);
// Use output values like result.test_module_output.virtual_network_name
// or build up known resource names with result.resource_code
// to retrieve resources and validate desired state has been achieved
result.teardown();
Sensitive Output
If an output variable from your test module contains sensitive value (i.e. has sensitive = true
in it), for example:
output "virtual_network_name" {
value = azurerm_virtual_network.example.name
sensitive = true
}
then you may get an error "Error: Output refers to sensitive values" indicating that the test_module_output
output variable must also be marked as sensitive. To do this pass true
to the sensitiveOutput
parameter of the relevant platform specific setup function setupAzureEnvironment
/setupAwsEnvironment
. This will ensure that the test module is setup with the correct sensitive outputs. Note that the value of any sensitive outputs are not shown in the logged resources initialized during test fixtures.