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

tests/ec2/ami: Rename tests #17849

Closed
wants to merge 2 commits into from
Closed

tests/ec2/ami: Rename tests #17849

wants to merge 2 commits into from

Conversation

YakDriver
Copy link
Member

@YakDriver YakDriver commented Feb 26, 2021

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates #17847

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccEC2AMI'
--- PASS: TestAccEC2AMI_basic (65.36s)
--- PASS: TestAccEC2AMI_description (78.83s)
--- PASS: TestAccEC2AMI_disappears (62.32s)
--- PASS: TestAccEC2AMI_ephemeralBlockDevices (65.77s)
--- PASS: TestAccEC2AMI_gp3BlockDevice (65.85s)
--- PASS: TestAccEC2AMI_tags (94.55s)
--- PASS: TestAccEC2AMICopy_basic (387.25s)
--- PASS: TestAccEC2AMICopy_description (407.28s)
--- PASS: TestAccEC2AMICopy_enaSupport (386.54s)
--- PASS: TestAccEC2AMICopy_tags (418.14s)
--- PASS: TestAccEC2AMIDataSource_gp3BlockDevice (63.30s)
--- PASS: TestAccEC2AMIDataSource_instanceStore (24.13s)
--- PASS: TestAccEC2AMIDataSource_localNameFilter (26.55s)
--- PASS: TestAccEC2AMIDataSource_natInstance (24.09s)
--- PASS: TestAccEC2AMIDataSource_windowsInstance (24.32s)
--- PASS: TestAccEC2AMIFromInstance_basic (249.92s)
--- PASS: TestAccEC2AMIFromInstance_tags (295.32s)
--- PASS: TestAccEC2AMIIDsDataSource_basic (19.11s)
--- PASS: TestAccEC2AMIIDsDataSource_sorted (39.36s)
--- PASS: TestAccEC2AMILaunchPermission_basic (341.01s)
--- PASS: TestAccEC2AMILaunchPermission_disappears_ami (358.68s)
--- PASS: TestAccEC2AMILaunchPermission_disappears_launchPermission (342.87s)
--- PASS: TestAccEC2AMILaunchPermission_disappears_launchPermission_public (343.12s)

@YakDriver YakDriver requested a review from a team as a code owner February 26, 2021 23:15
@ghost ghost added size/S Managed by automation to categorize the size of a PR. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Feb 26, 2021
@@ -39,7 +39,7 @@ func TestAccAWSAMICopy_basic(t *testing.T) {
})
}

func TestAccAWSAMICopy_Description(t *testing.T) {
func TestAccEC2AMICopy_description(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The current guidance for writing acceptance tests uses lowercase for "meta" tests like _basic and _disappears, but uppercase for attribute-based and other tests. Not sure if we should be following the documentation or updating the documentation to include more explicit guidance.

Copy link
Member Author

Choose a reason for hiding this comment

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

While Go conventions do allow for capitalized words after the underscore, they apply to types and methods on types. Drawing the analogy to what we're doing, it would be reasonable to apply the same logic. However, I do not think we should have capitalized words after underscores for one simple reason: a badly followed convention is worse than no convention at all. Currently, the capitalized word after an underscore is as likely to tell you nothing about the test as something. As a result, a clear, followable convention would be better. I vote for updating the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, the capitalized word after an underscore is as likely to tell you nothing about the test as something.

Can you please expand on this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, there are around about 1256 basic and disappears tests, which use the underscore-lowercase "meta" test convention. There are a further 1904 tests that use underscore-lowercase but many do not seem like "meta" tests:

TestAccAWSAPIGatewayUsagePlan_description()
TestAccAWSAPIGatewayMethod_customrequestvalidator()
TestAccAWSAPIGatewayIntegration_integrationType()
TestAccAWSEBSSnapshot_tags()
TestAccAWSEBSVolume_updateSize()
TestAccAWSEIP_instance()
TestAccAWSGlueTrigger_actions_notify()
TestAccAWSInstance_outpost()

Copy link
Contributor

Choose a reason for hiding this comment

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

We should enforce whatever standard we choose. In this case, I think we should pick a standard that improves understandability/readability first, and then update whatever documentation and Semgrep rules to enforce it

@@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceAwsAmiIds_basic(t *testing.T) {
func TestAccEC2AMIIDsDataSource_basic(t *testing.T) {
Copy link
Contributor

@bflad bflad Mar 1, 2021

Choose a reason for hiding this comment

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

What determines whether test naming should include a fully capitalized initialism? Should we enforce the standard?

I've personally leaned towards only capital first letters in test naming after the resource type underscores, even for initialisms, e.g. TestAccEc2AmiIdsDataSource_basic

Copy link
Member Author

@YakDriver YakDriver Mar 2, 2021

Choose a reason for hiding this comment

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

Unlike above, the Go convention is clear on this point:

Words in names that are initialisms or acronyms (e.g. "URL" or "NATO") have a consistent case. For example, "URL" should appear as "URL" or "url" (as in "urlPony", or "URLPony"), never as "Url".

Although the AWS SDK for Go breaks this rule a lot, I have seen efforts to change course and some of the newer APIs follow this rule occassionally. My vote is that we stick with convention and win the respect of Go coders naming-convention followers.

Copy link
Contributor

@bflad bflad Mar 2, 2021

Choose a reason for hiding this comment

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

If we are going to enforce this, we will need to manually enumerate all initialisms and maintain the list going forward. For example, what does sesv2 convert into?

I would prefer to see a proposal on that before really going down this route since it affects all code and testing contributions, otherwise it will be easy to escape out of the desired convention. I'm guessing it would need to be a text file with a list or a Go file with a slice of strings, but we will need to figure out how to ensure it is usable by tooling that needs it and ensure that all contributors know how to add to it and when that is necessary.

For what it is worth, not using initialisms allows you to easily convert snake_case to PascalCase and lowercase to Titlecase without additional logic to also bake in the conversions. Not saying that needs to be an end-all goal, but I'm not sure if folks are really chasing after this project's code for "correctness" in this sense. More likely folks are probably interested in functionality that has readable code and works.

Copy link
Member Author

@YakDriver YakDriver Mar 2, 2021

Choose a reason for hiding this comment

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

I'm specifically limiting the scope of changes to test names. We have non-breaking freedom with test names. However, fixing things in test names but not code introduces a level of inconsistency. For instance, removing "AWS" and "Aws" from test names but not all the resource names. Despite this issue, which I think is small, I love the idea of having one area where we have clean, Go convention adhereing names.

Following Go's conventions, the "V" would either be the next word and capitalized or an initial and capitalized ("Greengrass" is the way it is because AWS treats it as one word):

package testing name example
apigatewayv2 APIGatewayV2 func TestAccAPIGatewayV2GreatTest_basic
cloudhsmv2 CloudHSMV2 func TestAccCloudHSMV2GreatTest_basic
elbv2 ELBV2 func TestAccELBV2GreatTest_basic
greengrassv2 GreengrassV2 func TestAccGreengrassV2GreatTest_basic
kinesisanalyticsv2 KinesisAnalyticsV2 func TestAccKinesisAnalyticsV2GreatTest_basic
lexmodelsv2 LexModelsV2 func TestAccLexModelsV2GreatTest_basic
lexruntimev2 LexRuntimeV2 func TestAccLexRuntimeV2GreatTest_basic
sesv2 SESV2 func TestAccSESV2GreatTest_basic
wafv2 WAFV2 func TestAccWAFV2GreatTest_basic

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the <service>V2 approach in general. However, it doesn't look right after initialisms, such as WAFV2. For straight up consistency, I'd go with <service>V2. For ease of readability or aesthetics, I'd go with <full word service>V2 and <initialism service>v2.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can extract the list of initialisms from the SDK packages at service/<service package>/service.go files. The constant ServiceID could be checked for all-caps. There are some special cases, such as ACM PCA, where there's a space.

Copy link
Contributor

Choose a reason for hiding this comment

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

This also somewhat relates to another cleanup issue I'd like to open around standardizing service and resource naming in, e.g. error messages

@YakDriver YakDriver requested a review from bflad March 2, 2021 01:25
Copy link
Contributor

@anGie44 anGie44 left a comment

Choose a reason for hiding this comment

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

my view on topics covered:

(1) dropping Aws/AWS -- YES 🥳 .

(2) initialisms -- also leaning towards 🐫 Case (e.g. WafV2RuleGroup) as it seems initialisms are not uniformly defined w/in AWS and in the real-world. also maintaining a list of initialisms can prove tricky/subjective and easy to miss adding new ones to the docs when introduced in PRs (e.g. maintaining our list of Environment variables)

(3) test suffixes (e.g. _Basic, ContentHandling) -- maintain 🐫 Case; imo, case doesn't map to semantics too intuitively and guidance from our documentation can be easily overlooked (hmm though a linter can enforce using lowercase for our "meta" tests 🤔 ; seems to add more complexity tho); no preference on whether case after underscore is lower (_contentHandling) vs. upper (_ContentHandling)

@gdavison
Copy link
Contributor

gdavison commented Mar 2, 2021

One other comment on standardization: Where do we want to move DataSource in acceptance test naming? For test name pattern matching, it's sometimes helpful to have it at the beginning if you want to test only the resource (-run=TestAccAWSMskCluster_ or -run=TestAccDataSourceAWSMskCluster_), and easy enough to include for resource and datasource (-run=TestAcc(DataSource)?AWSMskCluster_. This was one case where having AWS helped with -run=TestAcc.*AWSMskCluster_)

@YakDriver
Copy link
Member Author

Where do we want to move DataSource in acceptance test naming?

@bflad suggests, and I heartily agree, that we should move "DataSource" to the end of the first clause, i.e., just before the underscore. Most of the time, the default should be to run both the resource and data source when changing either since there can be dependencies. This fascilitates that. We should be able to still run only one or the other with TestAccExample*DataSource and TestAccExample*[^DataSource].

@YakDriver
Copy link
Member Author

YakDriver commented Mar 3, 2021

Re: @anGie44

(2) initialisms -- also leaning towards 🐫 Case (e.g. WafV2RuleGroup) as it seems initialisms are not uniformly defined w/in AWS and in the real-world. also maintaining a list of initialisms can prove tricky/subjective and easy to miss adding new ones to the docs when introduced in PRs (e.g. maintaining our list of Environment variables)

I don't think that not capitalizing acronyms and initialisms will get rid of all lists. For example, if we decide that WafV2 is correct, how would automation fix Wafv2, WAFv2, and WAFV2 without knowing that Waf is a word?

There are about 50 initialisms and acronyms in common AWS use. We only use some of those in the AWS provider. I don't think it's an unreasonable burden to maintain a list. We will need to maintain a list anyway to fix mixed case as well.

Also, by adhereing to Go's well-established convention, we don't have to explain special, non-conforming Go naming rules. We certainly can and should explain that we follow convention but Go developers will expect it. Many contributors have been trying to adhere for years. Probably some of them forget that we're special.

Acronyms and initialism:

ACL
ACM
ACMPCA
AMI
API
CUR
DAX
DHCP
DLM
DMS
EBS
EC2
ECR
ECS
EFS
EKS
ELB
EMR
FMS
HSM
IAM
ID
IOPS
IP
IVS
KMS
MQ
MWAA
PI
QLDB
RAM
RDS
SES
SFN
SMS
SNS
SQS
SSM
SSO
SSOOIDC
STS
SWF
URL
VOD
VPC
WAF

@anGie44
Copy link
Contributor

anGie44 commented Mar 3, 2021

I don't think it's an unreasonable burden to maintain a list

I think you're right here 👍 i thought it was a bit rare in golang projects at first but totally overlooked what current linters already do 😅 e.g. https://github.com/golang/lint/blob/master/lint.go#L767-L809. Which then makes me wonder, since we already get those for free from a linter like golint which could be enabled in our .golangci.yml file, could we just build off of that list i.e. just keep track of the AWS service initialisms. Or enabling that linter creates more warnings than we need to get this proposal started? Additionally, users (via their PRs: https://github.com/golang/lint/pulls) in the go community seem to be wanting to add to that initialisms list. So do we follow a similar pattern, say if DB is added, do we also update our tests when the time comes?

So let's say we go with the idea of having a list of initialisms/acronyms we see fit, i still have a couple Q's and perhaps I'm alluding to an additional PR where our conventions are documented to help the team but also contributors to this tech-debt issue:

  1. what do they [intialisms] look like in code (e.g. Go enumerations)?
  2. where will those initialisms live? (could be answered by 1.)
  3. what do our new naming conventions/mappings look like e.g. mapping of waf -> WAF?
  4. What do these initialisms apply to? only test functions for the moment? what about initialisms used in the resource and datasource files?
  5. if we want to enforce conventions within the community, how do we enforce the mapping when changing pre-existing tests vs. new tests? are we set on say using semgrep or another linter tool mentioned in the original issue, and how does that look like (can be a brief example). seems like that could also be a contributing factor as well if one of the end goals is to use the 🤖 🧠 to do the chore of updating tests in bulk where needed.

p.s. thank you for taking this on @YakDriver and taking this naming convo from the abstract to more tangible examples!

@YakDriver
Copy link
Member Author

@anGie44 Thanks, Angie! 🙏 🙏

It would be awesome to just use industry-standard linters! Maybe as a first step we could just lint test files and then eventually move to the resource and data source files. I like the idea of just feeding an iinitialism/acronym list to the linter that the community can help maintain!

  1. what do they [intialisms] look like in code (e.g. Go enumerations)?

The rules are the same. "Capitalisms" (my word for abbreviations, initialisms, acronyms, etc.) should be either all caps or all lowercase.

vpcCount := 0
namedVPC := "vpc"

We have a few complexities here that maybe are not exactly handled in the convention though, e.g., IoT.

  1. where will those initialisms live? (could be answered by 1.)

Somewhere in the repo, where we can feed them to the linter(s).

  1. what do our new naming conventions/mappings look like e.g. mapping of waf -> WAF?

Right now, I would expect to handle "WAF" the same as "EBS", "VPC", or "EC2".

  1. What do these initialisms apply to? only test functions for the moment? what about initialisms used in the resource and datasource files?

I think we start with tests. It's beyond the scope of this effort but we can turn on the the enforcement just for tests to get going. I have a script that can fix acceptance test names to avoid this taking much engineering time.

how does that look

As I'm not sure which direction we're going or if we'll even make any initialism changes, I haven't spent much time on enforcement. I'd be happy to collaborate if you have ideas!

@github-actions github-actions bot added this to the v3.64.0 milestone Oct 14, 2021
@github-actions
Copy link

github-actions bot commented Nov 4, 2021

This functionality has been released in v3.64.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@ewbankkit ewbankkit deleted the td-ami-test-rename branch March 3, 2022 21:11
@ewbankkit ewbankkit restored the td-ami-test-rename branch March 3, 2022 21:11
@ewbankkit ewbankkit deleted the td-ami-test-rename branch March 3, 2022 21:27
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/ec2 Issues and PRs that pertain to the ec2 service. size/S Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants