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

Expose internal SDKv2 Diff cross-test interface #2720

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

VenelinMartinov
Copy link
Contributor

@VenelinMartinov VenelinMartinov commented Dec 11, 2024

This is a test-only change. It exposes an internal Diff cross-test interface for the SDKv2 bridge. It currently just calls the runDiffCheck function.

@VenelinMartinov VenelinMartinov changed the title Expose internal Diff cross-test interface Expose internal SDKv2 Diff cross-test interface Dec 11, 2024
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.64%. Comparing base (7b3ace6) to head (5fec1c6).
Report is 7 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2720   +/-   ##
=======================================
  Coverage   69.63%   69.64%           
=======================================
  Files         301      301           
  Lines       38725    38725           
=======================================
+ Hits        26967    26970    +3     
+ Misses      10240    10238    -2     
+ Partials     1518     1517    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pkg/internal/tests/cross-tests/diff.go Outdated Show resolved Hide resolved
}

func Diff(
t T, resource *schema.Resource, config1, config2 map[string]cty.Value, opts ...DiffOption,
Copy link
Member

Choose a reason for hiding this comment

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

Create and Configure both take a map[string]*schema.Schema instead of a *schema.Resource. This is to intentionally constrain the inputs to Diff to only options that can be exercised in Diff based tests.

We will probably want an option for schema.Resource.CustomizeDiff. We don't want users to be able to set schema.Resource.Importer.

Copy link
Contributor Author

@VenelinMartinov VenelinMartinov Dec 12, 2024

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.

Copy link
Contributor Author

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 test

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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

Because it keeps the tests intentional. We only add properties that can actually be tested.

it works well enough and allows us to copy-paste provider examples and avoids unnecessary complexity.

I'd rather we didn't copy-paste whole resources to test only a small part of them.

I don't see what Resource.Importer has to do with Diff test

Nothing at all, but I can set .Importer on a *schema.Resource and pass that to crosstests.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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

passing *schema.Resource directly makes the tests easier to write but harder to read.

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.

@VenelinMartinov VenelinMartinov force-pushed the vvm/sdkv2_diff_cross_test_interface branch from 1668a0c to 899f5d0 Compare December 12, 2024 12:39
@VenelinMartinov VenelinMartinov merged commit fbed0aa into master Dec 13, 2024
17 checks passed
@VenelinMartinov VenelinMartinov deleted the vvm/sdkv2_diff_cross_test_interface branch December 13, 2024 14:01
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.98.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants