add separate CheckPriorProvider entry point

pull/37001/head
James Bardin 1 year ago
parent d016070564
commit 29fa9c401f

@ -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() {

@ -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)

@ -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
}

Loading…
Cancel
Save