Terratest是一个开源的Go语言库,可更轻松地为基础设施代码编写自动化测试。它为通用基础设施的测试任务提供了各种帮助函数和模式,其中包括:
测试Terraform代码
测试打包器模板
测试Docker镜像
通过SSH在服务器上执行命令
使用AWSAPI
发送HTTP请求
运行shell命令
这里有一个简单的例子来说明如何测试一些Terraform代码:
terraformOptios := &terraform.Optios { // The path to where your Terraform code is located TerraformDir: "../examples/terraform-basic-example",}// At the ed of the test, ru `terraform destroy` to clea up ay resources that were createddefer terraform.Destroy(t, terraformOptios)// This will ru `terraform iit` ad `terraform apply` ad fail the test if there are ay errorsterraform.IitAdApply(t, terraformOptios)// Validate your code works as expectedvalidateServerIsWorkig(t, terraformOptios)
评论