github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/test/azure/terraform_azure_functionapp_example_test.go (about) 1 //go:build azure 2 // +build azure 3 4 // NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for 5 // CircleCI. 6 7 package test 8 9 import ( 10 "strings" 11 "testing" 12 13 "github.com/gruntwork-io/terratest/modules/azure" 14 "github.com/gruntwork-io/terratest/modules/random" 15 "github.com/gruntwork-io/terratest/modules/terraform" 16 "github.com/stretchr/testify/assert" 17 ) 18 19 func TestTerraformAzureFunctionAppExample(t *testing.T) { 20 t.Parallel() 21 22 //_random := strings.ToLower(random.UniqueId()) 23 uniquePostfix := strings.ToLower(random.UniqueId()) 24 25 // website::tag::1:: Configure Terraform setting up a path to Terraform code. 26 terraformOptions := &terraform.Options{ 27 TerraformDir: "../../examples/azure/terraform-azure-functionapp-example", 28 Vars: map[string]interface{}{ 29 "postfix": uniquePostfix, 30 }, 31 } 32 // website::tag::5:: At the end of the test, run `terraform destroy` to clean up any resources that were created 33 defer terraform.Destroy(t, terraformOptions) 34 35 // website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors. 36 terraform.InitAndApply(t, terraformOptions) 37 38 // website::tag::3:: Run `terraform output` to get the values of output variables 39 resourceGroupName := terraform.Output(t, terraformOptions, "resource_group_name") 40 appName := terraform.Output(t, terraformOptions, "function_app_name") 41 42 appId := terraform.Output(t, terraformOptions, "function_app_id") 43 appDefaultHostName := terraform.Output(t, terraformOptions, "default_hostname") 44 appKind := terraform.Output(t, terraformOptions, "function_app_kind") 45 46 // website::tag::4:: Assert 47 assert.True(t, azure.AppExists(t, appName, resourceGroupName, "")) 48 site := azure.GetAppService(t, appName, resourceGroupName, "") 49 50 assert.Equal(t, appId, *site.ID) 51 assert.Equal(t, appDefaultHostName, *site.DefaultHostName) 52 assert.Equal(t, appKind, *site.Kind) 53 54 assert.NotEmpty(t, *site.OutboundIPAddresses) 55 assert.Equal(t, "Running", *site.State) 56 }