-
Notifications
You must be signed in to change notification settings - Fork 44
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
Expose internal SDKv2 Diff cross-test interface #2720
Merged
Merged
Changes from all commits
Commits
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
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,39 @@ | ||
package crosstests | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/zclconf/go-cty/cty" | ||
|
||
crosstestsimpl "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/internal/tests/cross-tests/impl" | ||
) | ||
|
||
type diffOpts struct { | ||
deleteBeforeReplace bool | ||
} | ||
|
||
// An option that can be used to customize [Diff]. | ||
type DiffOption func(*diffOpts) | ||
|
||
// DiffDeleteBeforeReplace specifies whether to delete the resource before replacing it. | ||
func DiffDeleteBeforeReplace(deleteBeforeReplace bool) DiffOption { | ||
return func(o *diffOpts) { o.deleteBeforeReplace = deleteBeforeReplace } | ||
} | ||
|
||
func Diff( | ||
t T, resource *schema.Resource, config1, config2 map[string]cty.Value, opts ...DiffOption, | ||
) crosstestsimpl.DiffResult { | ||
o := &diffOpts{} | ||
for _, opt := range opts { | ||
opt(o) | ||
} | ||
|
||
config1Cty := cty.ObjectVal(config1) | ||
config2Cty := cty.ObjectVal(config2) | ||
|
||
return runDiffCheck(t, diffTestCase{ | ||
Resource: resource, | ||
Config1: config1Cty, | ||
Config2: config2Cty, | ||
DeleteBeforeReplace: o.deleteBeforeReplace, | ||
}) | ||
} |
Oops, something went wrong.
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.
Create
andConfigure
both take amap[string]*schema.Schema
instead of a*schema.Resource
. This is to intentionally constrain the inputs toDiff
to only options that can be exercised inDiff
based tests.We will probably want an option for
schema.Resource.CustomizeDiff
. We don't want users to be able to setschema.Resource.Importer
.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.
Yeah, this unfortunately limits the expressiveness of the test too - for example custom Create and Update methods might be required in a Diff test for implementing Computed properties. Instead of re-implementing the API with options we should have a simple check for the banned inputs. In the case of Diff tests, I don't think there are any schema inputs which should be banned - this only applies to, for example, custom Create in Create cross-tests.
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 don't see what
Resource.Importer
has to do with Diff testThere 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 don't see a good reason why we would choose to add a new interface there for specifying schemas instead of reusing the default TF SDK one - it works well enough and allows us to copy-paste provider examples and avoids unnecessary complexity.
I can add refactoring the other cross-test interfaces to my TODO list
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 on the side of being more permissive here in the internal test 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.
Because it keeps the tests intentional. We only add properties that can actually be tested.
I'd rather we didn't copy-paste whole resources to test only a small part of them.
Nothing at all, but I can set
.Importer
on a*schema.Resource
and pass that tocrosstests.Diff
with this design. I'd rather that was a compiler error. I use that example because I remember someone setting.Importer
for a create and asserting that the.Importer
didn't panic.I won't block the PR on this, but IMO passing
*schema.Resource
directly makes the tests easier to write but harder to read.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 don't agree about readability either. I think the benefit of options is that it is harder to get the Schema wrong. Given that there's very few people who actually write these type of tests, I think it's worth keeping it simple for now and evolving the interface once we find a need to.
Let's revisit once we have a concrete problem we are solving with the extra interface.