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

Add extract schema inputs tests for sdkv2 #2224

Merged
merged 2 commits into from
Jul 23, 2024

Conversation

VenelinMartinov
Copy link
Contributor

@VenelinMartinov VenelinMartinov commented Jul 22, 2024

This adds test cases for how TF types are handled by ExtractInputsFromOutputs in combination with Default and Computed and MaxItems: 1
ExtractInputsFromOutputs is the function in schema.go responsible for generating the inputs from resource outputs when a resource is imported. Its output is what the engine then uses for generating the code for the import.

Notably, nested computed values are wrong for both max items one and non-max items one.

In #2180 we found a regression there, so this fills in some missing coverage.
Extracting the tests to make the changes more apparent and to make sure we don't regress in #2181

Copy link

codecov bot commented Jul 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.49%. Comparing base (c57aebd) to head (773f796).
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2224      +/-   ##
==========================================
+ Coverage   60.66%   62.49%   +1.82%     
==========================================
  Files         356      355       -1     
  Lines       46430    38625    -7805     
==========================================
- Hits        28169    24137    -4032     
+ Misses      16701    12927    -3774     
- Partials     1560     1561       +1     

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

Copy link
Contributor

@guineveresaenger guineveresaenger left a comment

Choose a reason for hiding this comment

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

non-blocking:

Can you give an explicit summary in the PR description for what exactly these tests are testing? Three months from now we'll really appreciate the context.

Copy link
Contributor

@guineveresaenger guineveresaenger left a comment

Choose a reason for hiding this comment

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

similarly: can the test names be a bit more descriptive too? It's a lot of tests and I'd like to see names such as TestExtractInputsFromOutputsSdkv2/string_outputs_map_to_string_inputs or something like that. In a test suite, TestExtractInputsFromOutputsSdkv2/string is not that meaningful.

@VenelinMartinov VenelinMartinov enabled auto-merge (squash) July 23, 2024 04:59
@VenelinMartinov VenelinMartinov merged commit 7ccdd03 into master Jul 23, 2024
11 checks passed
@VenelinMartinov VenelinMartinov deleted the vvm/add_extract_schema_inputs_tests branch July 23, 2024 05:15
VenelinMartinov added a commit that referenced this pull request Jul 23, 2024
This adds adds missing test coverage for `ExtractInputsFromOutputs` for
various PF schemas. `ExtractInputsFromOutputs` is a shared function so
we should have coverage on both sides to make sure we don't cause
regressions when fixing one.

Similar to #2224
but on the PF side.

This is in preparation for
#2181 for
#2180.

Seeing some more evidence of
#2218 here.
VenelinMartinov added a commit that referenced this pull request Jul 23, 2024
Fixes an issue with the SDKv2 and PF input extraction. During import we
wrongly return values for properties which are fully computed which
causes invalid programs to be generated.

~The object check in `CastToTypeObject` was wrong for SDKV2 objects:
https://github.com/pulumi/pulumi-terraform-bridge/blob/48fd41bd16e2f7f933bb9390ab7619d52faabb6d/pkg/tfshim/util/types.go#L36~

The `CastToTypeObject` object check is wrong for both SDKv2 and PF. For
the SDKV2 only sets and lists can have a `Resource` `.Elem`. For PF it
list-nested blocks are represented with a `Resource` `.Elem` in the shim
layer, so the check did not catch these. PF details here:
#2231
This fixes the check and adds regression tests for the broken imports
which resulted from 2180.

Test coverage added in
#2224 for sdkv2
and #2225 for pf.
fixes #2180
depends on pulumi/providertest#91
stacked on #2225
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.88.0.

@mjeffryes mjeffryes added this to the 0.108 milestone Aug 16, 2024
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