0.7.4 • Published 12 days ago

@octopusdeploy/step-test-framework v0.7.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
12 days ago

step-test-framework

An opinionated testing frame work for testing Octopus Step Package Steps.

npm i @octopusdeploy/step-test-framework --save-dev

Build and Publish

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.

0.7.4

12 days ago

0.7.3

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.3.0

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.2.1

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago