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

[Repo]: Constants no longer used for number strings in test files #39881

Open
YakDriver opened this issue Oct 24, 2024 · 1 comment
Open

[Repo]: Constants no longer used for number strings in test files #39881

YakDriver opened this issue Oct 24, 2024 · 1 comment
Labels
repository Repository modifications; GitHub Actions, developer docs, issue templates, codeowners, changelog.

Comments

@YakDriver
Copy link
Member

YakDriver commented Oct 24, 2024

Description

TL;DR

We apologize for any inconvenience if your PR was broken by changes to constants in test files!

What happened:

  1. Number-string (e.g., "1") constants (e.g., acctest.Ct1) are no longer defined -- this only affects test files
  2. As you might guess, CI/Semgrep checks now don't enforce use of constants for number strings

Fixing your PR:

  • If your PR includes changes to test files, replace constants with number-strings, e.g., replacing acctest.Ct1 with "1" (see below for autofix instructions)

More details

Previously, in tests, we used number-string (e.g., "1") constants (e.g., acctest.Ct1) for common numbers:

resource.TestCheckResourceAttr(resourceName, "action.#", acctest.Ct1),

As maintainers, we made the decision that this pattern was not a net benefit and made the code harder to read. As a result, we have reverted all number-string constants back to number-strings in test files:

resource.TestCheckResourceAttr(resourceName, "action.#", "1"),

Autofixing

Process 1

For most PRs, with changes in only a few test files, this is how to autofix your PR:

  1. Switch to the main branch and pull the latest
  2. Rebase your branch on the freshly pulled origin/main OR merge origin/main onto your branch
  3. Fix merge conflicts
  4. Run make fix-constants

This will replace constants throughout the test codebase with the right number string: e.g., acctest.Ct1 will be replaced with "1".

Process 2

For bigger PRs, affecting many test files, this advanced approach can reduce the merge conflicts. In most cases, you should use Process 1.

  1. git checkout ed86924 -- GNUmakefile .ci/.semgrep-test-constants-temp.yml
  2. Run make fix-constants
  3. Switch to the main branch and pull the latest
  4. Rebase your branch on the freshly pulled origin/main OR merge origin/main onto your branch
  5. Fix merge conflicts

References

#39840

@YakDriver YakDriver added the repository Repository modifications; GitHub Actions, developer docs, issue templates, codeowners, changelog. label Oct 24, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repository Repository modifications; GitHub Actions, developer docs, issue templates, codeowners, changelog.
Projects
None yet
Development

No branches or pull requests

1 participant