From 29fa9c401f2c830c99ddb9f60ba68a142b70b10d Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 7 May 2025 13:27:02 -0400 Subject: [PATCH] add separate CheckPriorProvider entry point --- internal/lang/function_results.go | 11 ++++++++--- internal/lang/function_results_test.go | 6 +++--- internal/providers/functions.go | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/lang/function_results.go b/internal/lang/function_results.go index 615272fb2e..bd254501e0 100644 --- a/internal/lang/function_results.go +++ b/internal/lang/function_results.go @@ -43,9 +43,14 @@ func NewFunctionResultsTable(hashes []FunctionHash) *FunctionResults { } // CheckPrior compares the function call against any cached results, and returns -// an error if the result does not match a prior call. A zero-value provider -// address can be used for internal functions which need this validation. -func (f *FunctionResults) CheckPrior(provider addrs.Provider, name string, args []cty.Value, result cty.Value) error { +// an error if the result does not match a prior call. +func (f *FunctionResults) CheckPrior(name string, args []cty.Value, result cty.Value) error { + return f.CheckPriorProvider(addrs.Provider{}, name, args, result) +} + +// CheckPriorProvider compares the provider function call against any cached +// results, and returns an error if the result does not match a prior call. +func (f *FunctionResults) CheckPriorProvider(provider addrs.Provider, name string, args []cty.Value, result cty.Value) error { argSum := sha256.New() if !provider.IsZero() { diff --git a/internal/lang/function_results_test.go b/internal/lang/function_results_test.go index 22f4df4591..da5715738b 100644 --- a/internal/lang/function_results_test.go +++ b/internal/lang/function_results_test.go @@ -162,12 +162,12 @@ func TestFunctionCache(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprint(i), func(t *testing.T) { results := NewFunctionResultsTable(nil) - err := results.CheckPrior(test.first.provider, test.first.name, test.first.args, test.first.result) + err := results.CheckPriorProvider(test.first.provider, test.first.name, test.first.args, test.first.result) if err != nil { t.Fatal("error on first call!", err) } - err = results.CheckPrior(test.second.provider, test.second.name, test.second.args, test.second.result) + err = results.CheckPriorProvider(test.second.provider, test.second.name, test.second.args, test.second.result) if err != nil && !test.expectErr { t.Fatal(err) @@ -177,7 +177,7 @@ func TestFunctionCache(t *testing.T) { newResults := NewFunctionResultsTable(results.GetHashes()) originalErr := err != nil - reloadedErr := newResults.CheckPrior(test.second.provider, test.second.name, test.second.args, test.second.result) != nil + reloadedErr := newResults.CheckPriorProvider(test.second.provider, test.second.name, test.second.args, test.second.result) != nil if originalErr != reloadedErr { t.Fatalf("original check returned err:%t, reloaded check returned err:%t", originalErr, reloadedErr) diff --git a/internal/providers/functions.go b/internal/providers/functions.go index b16e8bad64..33fe846ec1 100644 --- a/internal/providers/functions.go +++ b/internal/providers/functions.go @@ -120,7 +120,7 @@ func (d FunctionDecl) BuildFunction(providerAddr addrs.Provider, name string, re } if resTable != nil { - err = resTable.CheckPrior(providerAddr, name, args, resp.Result) + err = resTable.CheckPriorProvider(providerAddr, name, args, resp.Result) if err != nil { return cty.UnknownVal(retType), err }