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

feat: ability to set value of API_DATA_IS_SENSITIVE to false #915

Merged
merged 4 commits into from
Jan 27, 2025

Conversation

Vipin654
Copy link
Contributor

Description

Ability to set API_DATA_IS_SENSITIVE to false so that if terraform detects some output value to be sensitive we can avoid the test failure.

Release required?

  • No release
  • Patch release (x.x.X)
  • Minor release (x.X.x)
  • Major release (X.x.x)
Release notes content

Run the pipeline

If the CI pipeline doesn't run when you create the PR, the PR requires a user with GitHub collaborators access to run the pipeline.

Run the CI pipeline when the PR is ready for review and you expect tests to pass. Add a comment to the PR with the following text:

/run pipeline

Checklist for reviewers

  • If relevant, a test for the change is included or updated with this PR.
  • If relevant, documentation for the change is included or updated with this PR.

For mergers

  • Use a conventional commit message to set the release level. Follow the guidelines.
  • Include information that users need to know about the PR in the commit message. The commit message becomes part of the GitHub release notes.
  • Use the Squash and merge option.

@Vipin654
Copy link
Contributor Author

/run pipeline

@Vipin654
Copy link
Contributor Author

/run pipeline

@Vipin654
Copy link
Contributor Author

/run pipeline

@@ -39,7 +39,10 @@ func (options *TestOptions) TestSetup() {
// testSetup Setup test
func (options *TestOptions) testSetup() {
if !options.SkipTestSetup {
os.Setenv("API_DATA_IS_SENSITIVE", "true")

if !options.ApiDataIsNonSensitive {
Copy link
Member

Choose a reason for hiding this comment

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

@toddgiguere, what do you think? I am not a big fan of the double negative, so I would switch to a pointer-based approach. For example:

type TestOptions struct {
    ApiDataIsSensitive *bool
    // ...
}
if options.ApiDataIsSensitive == nil {
    // Preserve old behavior
    os.Setenv("API_DATA_IS_SENSITIVE", "true")
} else {
    os.Setenv("API_DATA_IS_SENSITIVE", strconv.FormatBool(*options.ApiDataIsSensitive))
}

That way, leaving ApiDataIsSensitive as nil defaults to sensitive (old behavior), and setting it explicitly to true or false is straightforward.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, a pointer is probably the only way to go here, if it is not a pointer we have no way of determining if the caller didn't set it at all (took the default) or if they really did want it set to false. So I agree with the pointer idea.

Let me ask another question though, @ocofaigh I don't know the context of the original ask, but here is my question:
"Is there a legitimate reason why a unit test should EVER want this set to false"?

If the answer to the above is "maybe not" then another approach would be to check for the presense of this ENV and if it is not present then just set it to true. Don't even have the option to turn off.

Copy link
Member

Choose a reason for hiding this comment

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

@Vipin654 please go ahead with the suggested pointer-based implementation thanks

@Vipin654
Copy link
Contributor Author

/run pipeline

@ocofaigh ocofaigh merged commit 838f9d6 into main Jan 27, 2025
1 check passed
@ocofaigh ocofaigh deleted the API_DATA_NON_SENSITIVE branch January 27, 2025 15:23
@terraform-ibm-modules-ops
Copy link
Contributor

🎉 This PR is included in version 1.44.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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