-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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 acceptance and internal tests for gcs
backend, add some test helper functions
#35026
base: main
Are you sure you want to change the base?
Conversation
01757ad
to
c0622f8
Compare
c0622f8
to
ed83722
Compare
…doesn't affect use of ENV-supplied credentials
…rp/terraform PRs
… let checks pass in hashicorp/terraform repo.
f93c4f7
to
b5abe9f
Compare
Just rebased to include the latest gcs PR |
Move `TestBackendEncryptionKeyEmptyConflict` test to internal test file
5801a6d
to
e31ddb3
Compare
gcs
backend, add some test helper functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to approve this, the comments in my review are only superficial.
// getWantValue is required because the key input is changed internally in the backend's code | ||
// This function is a quick way to help us get a want value, but ideally in future the test and | ||
// the code under test will use a reusable function to avoid logic duplication. | ||
getWantValue := func(key string) []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you've made this a closure because you want access to the t
variable but you could just make this it's own func with testing.T
as a parameter.
edit: ah, you mention this in the comment above
getWantValue := func(key string) []byte { | ||
var want []byte | ||
if key == "" { | ||
want = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just return nil
here since the next conditional is key != ""
?
if key == "" { | ||
want = nil | ||
} | ||
if key != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just be else
or not even be a conditional if we just return early in the conditional above.
"GOOGLE_CREDENTIALS": credentials, | ||
}, | ||
}, | ||
// Uncomment below for sanity checking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably best not to merge in lines of commented out code – if this is a purposeful test it would be better to formulate it in a way that a failing test isn't the desired outcome.
preCheckEnvironmentVariables(t) | ||
// Cannot use t.Parallel as t.SetEnv used | ||
|
||
// getWantValue is required because the key input is changed internally in the backend's code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we are just copying convention used elsewhere in the codebase, but trying to parse "get want value" hurt my brain. We can leave as is, but I suspect the language we wanted to use here was expected
instead of want
.
if got := b.stateFile(c.name); got != c.wantStateFile { | ||
t.Errorf("stateFile(%q) = %q, want %q", c.name, got, c.wantStateFile) | ||
} | ||
// TODO - implement a separate function specific to credentials which will iterate through a list of ENV names and return first value found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a note to self to be answered in this PR, or for later?
Historically the
gcs
backend hasn't been touched much. In the past I've added a few features but largely left the existing codebase as it was previously. Recently thegcs
backend was refactored in #34989 to avoid using the old SDK.As part of reviewing that PR I started adding a few acceptance tests in this PR. There's a lot more work to be done but I want to avoid this PR getting too big.
This PR:
gcs
backend set up (//TODO!)TestBackendConfig_encryptionKey
- how the config and ENVs for customer-supplied encryption keys are usedTestBackendConfig_kmsKey
- how the config and ENVs for customer-managed (KMS) encryption keys are usedTestAccBackendConfig_credentials
- empty strings in the backend config don't interrupt use of ENVs for creds.Target Release
1.8.x
Draft CHANGELOG entry
NEW FEATURES | UPGRADE NOTES | ENHANCEMENTS | BUG FIXES | EXPERIMENTS