Skip to content

Add tests around how plugin framework provider configuration code handles credentials values#8801

Merged
SarahFrench merged 15 commits into
mainfrom
add-pf-credentials-tests
Sep 6, 2023
Merged

Add tests around how plugin framework provider configuration code handles credentials values#8801
SarahFrench merged 15 commits into
mainfrom
add-pf-credentials-tests

Conversation

@SarahFrench

@SarahFrench SarahFrench commented Aug 30, 2023

Copy link
Copy Markdown
Contributor

This PR adds tests for how the plugin framework config code handles the credentials field's value.
These tests either:

  • Are the PF equivalent of existing tests for the SDK provider config code
  • Are tests that currently don't pass, and will be made to pass in a future PR that makes the PF behaviour mimic the SDK's behaviour:
    • by ignoring empty strings
    • by treating unknown values as if they were null

Note: in this PR I changed the function signature for LoadAndValidateFramework (see comment here) to enable proper testing of the function

TODOs:

  • Add test cases to match SDK tests
  • Ensure tests present about handling empty strings (will not be passing, add link to related issue)
  • Ensure tests present about handling Unknown values (will not be passing, add link to related issue)

If this PR is for Terraform, I acknowledge that I have:

  • Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
  • Generated Terraform providers, and ran make test and make lint in the generated providers to ensure it passes unit and linter tests.
  • Ran relevant acceptance tests using my own Google Cloud project and credentials (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
  • Read Write release notes before writing my release note below.

Release Note Template for Downstream PRs (will be copied)


@SarahFrench SarahFrench changed the base branch from main to address-circular-dependencies-pf-config-tests August 30, 2023 14:47
@modular-magician

Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 10 files changed, 161 insertions(+), 158 deletions(-))
Terraform Beta: Diff ( 10 files changed, 161 insertions(+), 158 deletions(-))

// LoadAndValidateFramework handles the bulk of configuring the provider
// it is pulled out so that we can manually call this from our testing provider as well
func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context, data fwmodels.ProviderModel, tfVersion string, diags *diag.Diagnostics, providerversion string) {
func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context, data *fwmodels.ProviderModel, tfVersion string, diags *diag.Diagnostics, providerversion string) {

@SarahFrench SarahFrench Aug 30, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR isn't ready for full review yet, but flagging this change.

Currently the data about the provider's configuration in the config (ie provider block) is received by the provider code and used to populate the data *fwmodels.ProviderModel struct in this code. The data struct is only used by passing it into LoadAndValidateFramework, and isn't used elsewhere. Because it's only got this one use, I think this change doesn't have much risk associated with it.

Making the function take a pointer instead of a copied value allows the test to see how the data model struct is mutated inside this function.

@modular-magician

Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 3007
Passed tests 2709
Skipped tests: 296
Affected tests: 2

Action taken

Found 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccDataprocJobIamPolicy|TestAccProjectIamPolicy_invalidMembers

Get to know how VCR tests work

@modular-magician

Copy link
Copy Markdown
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccDataprocJobIamPolicy[Debug log]
TestAccProjectIamPolicy_invalidMembers[Debug log]

Rerun these tests in REPLAYING mode to catch issues

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{green}{\textsf{All tests passed!}}$
View the build log or the debug log for each test

@SarahFrench SarahFrench force-pushed the add-pf-credentials-tests branch from a450ef8 to 8b1f805 Compare August 31, 2023 00:03
@SarahFrench SarahFrench changed the base branch from address-circular-dependencies-pf-config-tests to main August 31, 2023 00:05
@SarahFrench SarahFrench marked this pull request as ready for review August 31, 2023 00:08
@SarahFrench

This comment was marked as outdated.

@modular-magician

This comment was marked as outdated.

@modular-magician

This comment was marked as outdated.

@modular-magician

This comment was marked as outdated.

@SarahFrench SarahFrench marked this pull request as draft August 31, 2023 01:15
@modular-magician

Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 6 files changed, 407 insertions(+), 11 deletions(-))
Terraform Beta: Diff ( 6 files changed, 407 insertions(+), 11 deletions(-))

@modular-magician

Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 3003
Passed tests 2709
Skipped tests: 294
Affected tests: 0

$\textcolor{red}{\textsf{Errors occurred during REPLAYING mode. Please fix them to complete your PR}}$
View the build log

@SarahFrench

This comment was marked as resolved.

@SarahFrench

This comment was marked as outdated.

@modular-magician

Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 6 files changed, 407 insertions(+), 11 deletions(-))
Terraform Beta: Diff ( 6 files changed, 407 insertions(+), 11 deletions(-))

@modular-magician

Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 3008
Passed tests 2712
Skipped tests: 296
Affected tests: 0

$\textcolor{green}{\textsf{All tests passed in REPLAYING mode.}}$
View the build log

@SarahFrench SarahFrench marked this pull request as ready for review August 31, 2023 17:59

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When the file was called mmv1/third_party/terraform/fwtransport/framework_config_test.erb it didn't get generated in the downstream at all. I totally blanked this in my PR that first introduced the file to MM, but there aren't any negative consequences beyond my tests not being present in the downstream yet.

Comment on lines +104 to +131
// Handling empty strings in config
// TODO(SarahFrench) make these tests pass to address: https://github.com/hashicorp/terraform-provider-google/issues/14255
// "when project is set as an empty string the field is treated as if it's unset, without error": {
// ConfigValues: fwmodels.ProviderModel{
// Project: types.StringValue(""),
// },
// ExpectedDataModelValue: types.StringNull(),
// ExpectedConfigStructValue: types.StringNull(),
// },
// "when project is set as an empty string an environment variable will be used": {
// ConfigValues: fwmodels.ProviderModel{
// Project: types.StringValue(""),
// },
// EnvVariables: map[string]string{
// "GOOGLE_PROJECT": "project-from-GOOGLE_PROJECT",
// },
// ExpectedDataModelValue: types.StringNull(),
// ExpectedConfigStructValue: types.StringValue("project-from-GOOGLE_PROJECT"),
// },
// Handling unknown values
// TODO(SarahFrench) make these tests pass to address: https://github.com/hashicorp/terraform-provider-google/issues/14444
// "when project is an unknown value, the provider treats it as if it's unset (align to SDK behaviour)": {
// ConfigValues: fwmodels.ProviderModel{
// Project: types.StringUnknown(),
// },
// ExpectedDataModelValue: types.StringNull(),
// ExpectedConfigStructValue: types.StringNull(),
// },

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll make these tests pass in a subsequent PR, for ease of review and to ensure that all these 'fixes' can be done at once later in a single PR instead of across multiple PRs

Comment thread mmv1/third_party/terraform/fwtransport/framework_config_test.go.erb Outdated
…o.erb

Co-authored-by: Riley Karson <rileykarson@google.com>
@modular-magician

Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

Terraform GA: Diff ( 6 files changed, 407 insertions(+), 11 deletions(-))
Terraform Beta: Diff ( 6 files changed, 407 insertions(+), 11 deletions(-))

@modular-magician

Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 3014
Passed tests 2717
Skipped tests: 296
Affected tests: 1

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
TestAccDataprocClusterIamPolicy

Get to know how VCR tests work

@modular-magician

Copy link
Copy Markdown
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccDataprocClusterIamPolicy[Debug log]

Rerun these tests in REPLAYING mode to catch issues

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{green}{\textsf{All tests passed!}}$
View the build log or the debug log for each test

@SarahFrench SarahFrench merged commit 356bf50 into main Sep 6, 2023
simonebruzzechesse pushed a commit to simonebruzzechesse/magic-modules that referenced this pull request Sep 7, 2023
…dles `credentials` values (GoogleCloudPlatform#8801)

* Add initial version of plugin framework provider config test affected by inaccessible functions

* Refactor provider config tests to use plugin-framework types

* Add test case about handling of Unknown values for `project`

* Update tests to check values in BOTH the data model and provider config struct after `LoadAndValidateFramework` runs

* Add some tests for `credentials` in plugin framework provider, including test case that fails

* Update `LoadAndValidateFramework` to take a pointer to the provider data model, so mutations to the data within the function change the original struct

This enables tests to track how the data is mutated

* Add remaining `credentials` test cases to check PF/SDK config parity

* Make tests unset ADC ENV automatically, update comments to tests setting ADC ENV

* Add test for behaviour when credentials value is unknown

* Add comment referring devs to where unknown value test is implemented

* Remove duplicated test case

* Fix filename so it's generated correctly

* Remove fmt line

* Update `project` tests that are affected by `LoadAndValidateFramework` now taking a pointer as an argument

* Update mmv1/third_party/terraform/fwtransport/framework_config_test.go.erb

Co-authored-by: Riley Karson <rileykarson@google.com>

---------

Co-authored-by: Riley Karson <rileykarson@google.com>
simonebruzzechesse pushed a commit to simonebruzzechesse/magic-modules that referenced this pull request Sep 7, 2023
…dles `credentials` values (GoogleCloudPlatform#8801)

* Add initial version of plugin framework provider config test affected by inaccessible functions

* Refactor provider config tests to use plugin-framework types

* Add test case about handling of Unknown values for `project`

* Update tests to check values in BOTH the data model and provider config struct after `LoadAndValidateFramework` runs

* Add some tests for `credentials` in plugin framework provider, including test case that fails

* Update `LoadAndValidateFramework` to take a pointer to the provider data model, so mutations to the data within the function change the original struct

This enables tests to track how the data is mutated

* Add remaining `credentials` test cases to check PF/SDK config parity

* Make tests unset ADC ENV automatically, update comments to tests setting ADC ENV

* Add test for behaviour when credentials value is unknown

* Add comment referring devs to where unknown value test is implemented

* Remove duplicated test case

* Fix filename so it's generated correctly

* Remove fmt line

* Update `project` tests that are affected by `LoadAndValidateFramework` now taking a pointer as an argument

* Update mmv1/third_party/terraform/fwtransport/framework_config_test.go.erb

Co-authored-by: Riley Karson <rileykarson@google.com>

---------

Co-authored-by: Riley Karson <rileykarson@google.com>
@SarahFrench SarahFrench deleted the add-pf-credentials-tests branch September 11, 2023 11:45
RileyHYZ pushed a commit to RileyHYZ/magic-modules that referenced this pull request Sep 15, 2023
…dles `credentials` values (GoogleCloudPlatform#8801)

* Add initial version of plugin framework provider config test affected by inaccessible functions

* Refactor provider config tests to use plugin-framework types

* Add test case about handling of Unknown values for `project`

* Update tests to check values in BOTH the data model and provider config struct after `LoadAndValidateFramework` runs

* Add some tests for `credentials` in plugin framework provider, including test case that fails

* Update `LoadAndValidateFramework` to take a pointer to the provider data model, so mutations to the data within the function change the original struct

This enables tests to track how the data is mutated

* Add remaining `credentials` test cases to check PF/SDK config parity

* Make tests unset ADC ENV automatically, update comments to tests setting ADC ENV

* Add test for behaviour when credentials value is unknown

* Add comment referring devs to where unknown value test is implemented

* Remove duplicated test case

* Fix filename so it's generated correctly

* Remove fmt line

* Update `project` tests that are affected by `LoadAndValidateFramework` now taking a pointer as an argument

* Update mmv1/third_party/terraform/fwtransport/framework_config_test.go.erb

Co-authored-by: Riley Karson <rileykarson@google.com>

---------

Co-authored-by: Riley Karson <rileykarson@google.com>
joelkattapuram pushed a commit to joelkattapuram/magic-modules that referenced this pull request Sep 20, 2023
…dles `credentials` values (GoogleCloudPlatform#8801)

* Add initial version of plugin framework provider config test affected by inaccessible functions

* Refactor provider config tests to use plugin-framework types

* Add test case about handling of Unknown values for `project`

* Update tests to check values in BOTH the data model and provider config struct after `LoadAndValidateFramework` runs

* Add some tests for `credentials` in plugin framework provider, including test case that fails

* Update `LoadAndValidateFramework` to take a pointer to the provider data model, so mutations to the data within the function change the original struct

This enables tests to track how the data is mutated

* Add remaining `credentials` test cases to check PF/SDK config parity

* Make tests unset ADC ENV automatically, update comments to tests setting ADC ENV

* Add test for behaviour when credentials value is unknown

* Add comment referring devs to where unknown value test is implemented

* Remove duplicated test case

* Fix filename so it's generated correctly

* Remove fmt line

* Update `project` tests that are affected by `LoadAndValidateFramework` now taking a pointer as an argument

* Update mmv1/third_party/terraform/fwtransport/framework_config_test.go.erb

Co-authored-by: Riley Karson <rileykarson@google.com>

---------

Co-authored-by: Riley Karson <rileykarson@google.com>
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.

3 participants