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

Adding Provider-Defined Function Testing #210

Merged
merged 16 commits into from
Mar 6, 2024
Merged

Conversation

bendbennett
Copy link
Contributor

Closes: #202

@bendbennett bendbennett added the enhancement New feature or request label Jan 30, 2024
"bool": {
Parameters: []*tfprotov6.FunctionParameter{
{
Name: "param",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

During the initial configuration of the Server() func to add functions, the Name field of the parameter was omitted, giving rise to the following error during execution of the TestAccV6FunctionBool test:

=== RUN   TestAccV6FunctionBool
    function_bool_test.go:17: Step 1/1 error: Error running pre-apply plan: exit status 1
        
        Error: Call to unknown function
        
          on terraform_plugin_test.tf line 13, in output "test":
          13: 					value = provider::corner::bool(true)
        
        There are no functions in namespace "provider::corner::".
--- FAIL: TestAccV6FunctionBool (0.55s)

Executing the test with TF_LOG=TRACE did not reveal that the issue was a consequence of the Name field being an empty string (refer to log output).

This is unlikely to be an issue from the standpoint of provider developers adding provider-defined functions as terraform-plugin-framework automatically adds the string "param" to function parameter Name fields, if the field is unpopulated, but I thought it might be worth mentioning in case the error generated by Terraform should be more explicit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would you be able to double check this with the latest alpha or beta1 (potentially releasing later today)? There was some work done in core to improve various function errors, e.g. hashicorp/terraform#34683

If it still doesn't seem reasonable, I would raise an issue in that issue tracker! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

go.mod Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

This is awesome!!! Looks great to me 🚀

Comment on lines +22 to +28
// Using 9223372036854775808, the smallest number that can't be represented as an int64,
// results in an Terraform error where [Planned value does not match config value for cty.NumberIntVal],
// which is related to a bug in go.cty relating to [Large integer comparisons and msgpack encoding].
// A value of 9223372036854775809 is used for the meanwhile.
//
// [Planned value does not match config value for cty.NumberIntVal]: https://github.com/hashicorp/terraform/issues/34589
// [Large integer comparisons and msgpack encoding]: https://github.com/zclconf/go-cty/pull/176
Copy link
Contributor

Choose a reason for hiding this comment

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

I super love/appreciate this additional code comment context! Looks like this has been closed out upstream and should be resolved as of Terraform 1.8.0-beta1, which I think means we can remove this comment now, but curious if you think this context needs to hang out anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree on the removal. I've also reverted the integer that's used in the test to 9223372036854775808.

I don't think we need to explicitly add anything relating to this issue/discovery within the terraform-provider-corner repository, and there's an issue which captures the context in terraform-plugin-framework, which I believe should be sufficient.

@@ -24,6 +24,7 @@ func TestSchemaResource_Float64Attribute_Precision(t *testing.T) {
Config: `resource "framework_float64_precision" "test" {
float64_attribute = 1 - 0.99
}`,
//nolint:staticcheck //Deprecated functions
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nit: I think these can be removed for now? 😄

"github.com/hashicorp/terraform-provider-corner/internal/backend"
)

var (
_ provider.ProviderWithFunctions = (*testProvider)(nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: This can be added to framework5provider for consistency 👍

tfversion.SkipBelow(tfversion.Version1_8_0),
},
ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){
//nolint:unparam // False positive in unparam related to map: https://github.com/mvdan/unparam/issues/40
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ having the actual false positive issue link here -- I think I've typically said something in the nolint comment about the error return being part of the required function signature in the past, but this is much clearer.

@bendbennett bendbennett merged commit eac47aa into main Mar 6, 2024
63 checks passed
@bendbennett bendbennett deleted the bendbennett/issues-202 branch March 6, 2024 16:34
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Provider-Defined Function Testing
2 participants