Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add servicebus #525

Merged
merged 16 commits into from
Sep 24, 2021
Merged

Add servicebus #525

merged 16 commits into from
Sep 24, 2021

Conversation

helayoty
Copy link
Contributor

Add Service Bus Azure module to terratest

@yorinasub17
Copy link
Contributor

Thanks for your contribution! Can you also add some tests for the functions, either unit or integration?

Note that while we want to add more support for Azure in terratest, we need some help to maintain the code, and we aren't planning on merging Azure contributions until we can figure out a way to run builds on Azure. Please take a look at #89 (comment) to learn more.

@brikis98 brikis98 added the Azure label Jun 26, 2020
@brikis98
Copy link
Member

Please see #89 for the status on Terratest with Azure. In particular, we're starting some work around it, and when that work is done, we'll be able to come back to this PR!

@helayoty helayoty reopened this Jan 26, 2021
@helayoty
Copy link
Contributor Author

@HadwaAbdelhalem The PR is ready for review

@helayoty
Copy link
Contributor Author

helayoty commented Jan 27, 2021

@helayoty
Copy link
Contributor Author

Issue #771

examples/azure/terraform-azure-servicebus-example/main.tf Outdated Show resolved Hide resolved
modules/azure/servicebus.go Outdated Show resolved Hide resolved
examples/azure/terraform-azure-servicebus-example/main.tf Outdated Show resolved Hide resolved
modules/azure/servicebus.go Outdated Show resolved Hide resolved
test/azure/terraform_azure_servicebus_example_test.go Outdated Show resolved Hide resolved
test/azure/terraform_azure_servicebus_example_test.go Outdated Show resolved Hide resolved
@helayoty
Copy link
Contributor Author

Copy link
Contributor

@HadwaAbdelhalem HadwaAbdelhalem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, minor last fix to get approved

@helayoty
Copy link
Contributor Author

helayoty commented Feb 5, 2021

HadwaAbdelhalem
HadwaAbdelhalem previously approved these changes Feb 5, 2021
Copy link
Contributor

@HadwaAbdelhalem HadwaAbdelhalem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @yorinasub17 the PR is ready for you review

Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM! Found a few minor issues that need to be fixed, but once those are addressed I think we can merge this in!

}
}
}
description = "All topics with the corresponding subscriptions"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: description should be first in the output block to be consistent with the other outputs.

return &sClient, nil
}

// ListServiceBusNamespaceE list all SB namespaces in all resource groups in the given subscription ID. This function would fail the test if there is an error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is incorrect with the function (E flavor returns errors, not fail the test). This applies to all functions in this file.

Suggested change
// ListServiceBusNamespaceE list all SB namespaces in all resource groups in the given subscription ID. This function would fail the test if there is an error.
// ListServiceBusNamespaceE list all SB namespaces in all resource groups in the given subscription ID.

return &results, nil
}

// ListServiceBusNamespace - list all SB namespaces in all resource groups in the given subscription ID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Non-E flavored functions should include the text that this would fail the test. This applies to all functions in this file.

return nil, err
}

results := make([]string, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: If we're using make, then this should use len(*sbNamespace) as the length/capacity and then set the values directly. Otherwise, it's more idiomatic to use results := []string{} or var results []string to define an empty slice.

if err != nil {
return nil, err
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: this code block is repeated between ListServiceBusNamespaceNamesE and ListServiceBusNamespaceNamesByResourceGroupE. Can you create an internal helper that plucks the namespace names given a slice of namespaces?

This comment applies also to ID attribute flavor.

}

// ListServiceBusNamespaceE list all SB namespaces in all resource groups in the given subscription ID. This function would fail the test if there is an error.
func ListServiceBusNamespaceE(subscriptionID string) (*[]servicebus.SBNamespace, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you switch these slice pointer return values to simple slices (applies to all functions in this file)? Note that slices are already pointers so you can still return nil.

In general, we try to avoid usage of pointers, especially pointers to slices as it leads to increased complexity unless it is necessary. For example, in this case you will have to do nil checks whenever you access these slices as nil is no longer equivalent to [] and the dereference in the range calls can lead to panics. Additionally, slice pointers are most useful when you want to pass by reference, and the use case for that is usually limited to function args.


results := make([]string, 0)
for _, namespace := range *sbNamespace {
results = append(results, *namespace.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use safePtrToString when dereferencing string ptr attributes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HadwaAbdelhalem looks like this comment wasn't addressed. I'm assuming that's because there is some guarantee in the SDK that ensures this is set. Is that correct assumption?

Copy link
Contributor

@HadwaAbdelhalem HadwaAbdelhalem Sep 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yorinasub17 it is, the SDK is calling the Azure Rest API underneath for all resources operations, and the validation of the name as a required parameter is done on the rest API Here

Comment on lines 88 to 90
if err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed as there is no new err definition in the for loop.

Comment on lines 116 to 118
if err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed as there is no new err definition in the for loop.

Comment on lines 176 to 178
if err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed as there is no new err definition in the for loop.

Comment on lines 203 to 205
if err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed as there is no new err definition in the for loop.

Comment on lines 303 to 305
if err != nil {
return nil, err
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed as there is no new err definition in the for loop.

@HadwaAbdelhalem
Copy link
Contributor

Hi @yorinasub17 I updated the PR to address your comments, please review when you get a chace. Here is a link to the CI . the failure is related to the ACI test and I will fix in a separate PR.

yorinasub17
yorinasub17 previously approved these changes Sep 16, 2021
Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Had 2 comments, but they are very minor issues so no need to block the PR.

Let me kick off a sanity check build to make sure it passes our precommit checks and if it does, we can merge this in!


results := make([]string, 0)
for _, namespace := range *sbNamespace {
results = append(results, *namespace.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HadwaAbdelhalem looks like this comment wasn't addressed. I'm assuming that's because there is some guarantee in the SDK that ensures this is set. Is that correct assumption?


for iteratorSubscription.NotDone() {
results = append(results, iteratorSubscription.Value())
err = iteratorSubscription.Next()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: This should really be err := iteratorSubscription.Next(), or even better is:

if err := iteratorSubscription.Next(); err != nil {
    return nil, err
}

so that it defines a new err var scoped to the forloop/if block. This is a general go pattern to avoid mistakes arising from overriding variables unintentionally.

This applies to the other sections as well.

@yorinasub17
Copy link
Contributor

yorinasub17 commented Sep 16, 2021

Ah looks like the precommit hook failed on running gofmt. Can you run gofmt on modules/azure/servicebus_test.go?

Here is the diff:

diff --git a/modules/azure/servicebus_test.go b/modules/azure/servicebus_test.go
index 25c3aad4..f96077dd 100644
--- a/modules/azure/servicebus_test.go
+++ b/modules/azure/servicebus_test.go
@@ -18,7 +18,7 @@ func TestListServiceBusNamespaceNamesE(t *testing.T) {
 
 	subscriptionID := ""
 
-	_, err :=  ListServiceBusNamespaceNamesE(subscriptionID)
+	_, err := ListServiceBusNamespaceNamesE(subscriptionID)
 	require.Error(t, err)
 }
 
@@ -28,7 +28,7 @@ func TestListServiceBusNamespaceIDsByResourceGroupE(t *testing.T) {
 	subscriptionID := ""
 	resourceGroup := ""
 
-	_, err :=  ListServiceBusNamespaceIDsByResourceGroupE(subscriptionID, resourceGroup)
+	_, err := ListServiceBusNamespaceIDsByResourceGroupE(subscriptionID, resourceGroup)
 	require.Error(t, err)
 }
 
@@ -39,7 +39,7 @@ func TestListNamespaceAuthRulesE(t *testing.T) {
 	namespace := ""
 	resourceGroup := ""
 
-	_, err :=  ListNamespaceAuthRulesE(subscriptionID, namespace, resourceGroup)
+	_, err := ListNamespaceAuthRulesE(subscriptionID, namespace, resourceGroup)
 	require.Error(t, err)
 }
 
@@ -50,7 +50,7 @@ func TestListNamespaceTopicsE(t *testing.T) {
 	namespace := ""
 	resourceGroup := ""
 
-	_, err :=  ListNamespaceTopicsE(subscriptionID, namespace, resourceGroup)
+	_, err := ListNamespaceTopicsE(subscriptionID, namespace, resourceGroup)
 	require.Error(t, err)
 }
 
@@ -62,7 +62,7 @@ func TestListTopicAuthRulesE(t *testing.T) {
 	resourceGroup := ""
 	topicName := ""
 
-	_, err :=  ListTopicAuthRulesE(subscriptionID, namespace, resourceGroup, topicName)
+	_, err := ListTopicAuthRulesE(subscriptionID, namespace, resourceGroup, topicName)
 	require.Error(t, err)
 }
 
@@ -76,4 +76,4 @@ func TestListTopicSubscriptionsNameE(t *testing.T) {
 
 	_, err := ListTopicSubscriptionsNameE(subscriptionID, namespace, resourceGroup, topicName)
 	require.Error(t, err)
-}
\ No newline at end of file
+}

Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates LGTM! I'll kick off another sanity check build.

Copy link
Contributor

@yorinasub17 yorinasub17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed the precommit hooks! @HadwaAbdelhalem Let me know if this is ready to merge (in particular, if the Azure build passed for you).

@HadwaAbdelhalem
Copy link
Contributor

HadwaAbdelhalem commented Sep 24, 2021

Thank you @yorinasub17 for checking it. it is ready for merge, the CI has a failed test that is unrelated to this PR. It is the TestTerraformAzureACIExample is failing duo to a change in the MS container images move to MCR . I created an Issue to track the ACI failure and will submit a fix for later today

@yorinasub17
Copy link
Contributor

Thanks! Will merge this in and release!

@yorinasub17 yorinasub17 merged commit c321790 into gruntwork-io:master Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants