forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from helayoty/dev/service-bus-terratest
Add tests and terraform module for service bus
- Loading branch information
Showing
3 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// +build azure | ||
|
||
// NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for | ||
// CircleCI. | ||
package azure | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
/* | ||
The below tests are currently stubbed out, with the expectation that they will throw errors. These tests can be extended. | ||
*/ | ||
func TestListServiceBusNamespaceNamesE(t *testing.T) { | ||
t.Parallel() | ||
|
||
subscriptionID := "" | ||
|
||
_, err := ListServiceBusNamespaceNamesE(subscriptionID) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestListServiceBusNamespaceIDsByResourceGroupE(t *testing.T) { | ||
t.Parallel() | ||
|
||
subscriptionID := "" | ||
resourceGroup := "" | ||
|
||
_, err := ListServiceBusNamespaceIDsByResourceGroupE(subscriptionID, resourceGroup) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestListNamespaceAuthRulesE(t *testing.T) { | ||
t.Parallel() | ||
|
||
subscriptionID := "" | ||
namespace := "" | ||
resourceGroup := "" | ||
|
||
_, err := ListNamespaceAuthRulesE(subscriptionID, namespace, resourceGroup) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestListNamespaceTopicsE(t *testing.T) { | ||
t.Parallel() | ||
|
||
subscriptionID := "" | ||
namespace := "" | ||
resourceGroup := "" | ||
|
||
_, err := ListNamespaceTopicsE(subscriptionID, namespace, resourceGroup) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestListTopicAuthRulesE(t *testing.T) { | ||
t.Parallel() | ||
|
||
subscriptionID := "" | ||
namespace := "" | ||
resourceGroup := "" | ||
topicName := "" | ||
|
||
_, err := ListTopicAuthRulesE(subscriptionID, namespace, resourceGroup, topicName) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestListTopicSubscriptionsNameE(t *testing.T) { | ||
t.Parallel() | ||
|
||
subscriptionID := "" | ||
namespace := "" | ||
resourceGroup := "" | ||
topicName := "" | ||
|
||
_, err := ListTopicSubscriptionsNameE(subscriptionID, namespace, resourceGroup, topicName) | ||
require.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// +build azure | ||
|
||
// NOTE: We use build tags to differentiate azure testing because we currently do not have azure access setup for | ||
// CircleCI. | ||
|
||
package test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"os" | ||
|
||
"github.com/gruntwork-io/terratest/modules/azure" | ||
"github.com/gruntwork-io/terratest/modules/random" | ||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTerraformAzureServiceBusExample(t *testing.T) { | ||
t.Parallel() | ||
|
||
uniquePostfix := strings.ToLower(random.UniqueId()) | ||
|
||
// website::tag::1:: Configure Terraform setting up a path to Terraform code. | ||
terraformOptions := &terraform.Options{ | ||
// The path to where our Terraform code is located | ||
TerraformDir: "../../examples/azure/terraform-azure-servicebus-example", | ||
Vars: map[string]interface{}{ | ||
"postfix": uniquePostfix, | ||
}, | ||
} | ||
|
||
// website::tag::4:: At the end of the test, run `terraform destroy` to clean up any resources that were created | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// website::tag::2:: Run `terraform init` and `terraform apply`. Fail the test if there are any errors. | ||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
// website::tag::3:: Run `terraform output` to get the values of output variables | ||
expectedTopicSubscriptionsMap := terraform.OutputMapOfObjects(t, terraformOptions, "topics") | ||
expectedNamespaceName := terraform.Output(t, terraformOptions, "namespace_name") | ||
expectedResourceGroup := terraform.Output(t, terraformOptions, "resource_group") | ||
|
||
for topicName, topicsMap := range expectedTopicSubscriptionsMap { | ||
subscriptionNamesFromAzure, err := azure.ListTopicSubscriptionsNameE( | ||
os.Getenv("ARM_SUBSCRIPTION_ID"), | ||
expectedNamespaceName, | ||
expectedResourceGroup, | ||
topicName) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
subscriptionsMap := topicsMap.(map[string]interface{})["subscriptions"].(map[string]interface{}) | ||
subscriptionNamesFromOutput := getMapKeylist(subscriptionsMap) | ||
// each subscription from the output should also exist in Azure | ||
assert.Equal(t, len(*subscriptionNamesFromOutput), len(*subscriptionNamesFromAzure)) | ||
for _, subscrptionName := range *subscriptionNamesFromOutput { | ||
assert.Contains(t, *subscriptionNamesFromAzure, subscrptionName) | ||
} | ||
} | ||
} | ||
|
||
func getMapKeylist(mapList map[string]interface{}) *[]string { | ||
names := make([]string, 0) | ||
for key := range mapList { | ||
names = append(names, key) | ||
} | ||
return &names | ||
} |