-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Improve tests for SDK-based util functions, add tests to the new plugin framework equivalents #7555
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
466042a
Add unit tests for `getProject` util
SarahFrench 5bf561d
Refactor existing `TestGetZone` test
SarahFrench 9880519
Move existing `getRegionFromZone` test alongside other util unit tests
SarahFrench 225c151
Rename `getRegionFromZone` unit test
SarahFrench 648333f
Refactor `TestGetRegion` unit test
SarahFrench 097f2a1
Simplify acc test setup code
SarahFrench 2abb624
Change unit test to use subtests via `t.Run`
SarahFrench ca33bba
Add unit test for `getProjectFramework` util function
SarahFrench b27886c
Fix comment
SarahFrench e165f14
Update test to set null value more explicitly using `types.StringNull()`
SarahFrench 214a80c
Replace example schema for test
SarahFrench File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
mmv1/third_party/terraform/framework_utils/framework_utils_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package google | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
func TestGetProjectFramework(t *testing.T) { | ||
cases := map[string]struct { | ||
ResourceProject types.String | ||
ProviderProject types.String | ||
ExpectedProject types.String | ||
ExpectedError bool | ||
}{ | ||
"project is pulled from the resource config value instead of the provider config value, even if both set": { | ||
ResourceProject: types.StringValue("foo"), | ||
ProviderProject: types.StringValue("bar"), | ||
ExpectedProject: types.StringValue("foo"), | ||
}, | ||
"project is pulled from the provider config value when unset on the resource": { | ||
ResourceProject: types.StringNull(), | ||
ProviderProject: types.StringValue("bar"), | ||
ExpectedProject: types.StringValue("bar"), | ||
}, | ||
"error when project is not set on the provider or the resource": { | ||
ExpectedError: true, | ||
}, | ||
} | ||
for tn, tc := range cases { | ||
t.Run(tn, func(t *testing.T) { | ||
// Arrange | ||
var diags diag.Diagnostics | ||
|
||
// Act | ||
project := getProjectFramework(tc.ResourceProject, tc.ProviderProject, &diags) | ||
|
||
// Assert | ||
if diags.HasError() { | ||
if tc.ExpectedError { | ||
return | ||
} | ||
t.Fatalf("Got %d unexpected error(s) during test: %s", diags.ErrorsCount(), diags.Errors()) | ||
} | ||
|
||
if project != tc.ExpectedProject { | ||
t.Fatalf("Incorrect project: got %s, want %s", project, tc.ExpectedProject) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 moved this test to a different file as it's not really a 'provider' test, though that may have made sense at the time this code was written!
It's now called
TestGetRegionFromZone