mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
lang/evalglue: Different approach to EvalContext defaults for tests
In other packages we've tried being pragmatic by making the main code compensate for missing arguments in older tests, so that we don't always need to update every test across the whole system every time we add a new feature. However, that compromise unfortunately tends to lead to non-test code inadvertently relying on the compensations too, so this is an attempt at a slightly different compromise where the main code will panic if called incorrectly but there's an extra helper function for tests to fill in reasonable "inert" defaults for the fields they leave unpopulated. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/opentofu/opentofu/internal/configs"
|
||||
"github.com/opentofu/opentofu/internal/configs/configschema"
|
||||
"github.com/opentofu/opentofu/internal/lang/eval"
|
||||
"github.com/opentofu/opentofu/internal/lang/eval/internal/evalglue"
|
||||
"github.com/opentofu/opentofu/internal/providers"
|
||||
)
|
||||
|
||||
@@ -65,7 +66,7 @@ func BenchmarkManyResourceInstances(b *testing.B) {
|
||||
// Since there are two resources, there are 2*instanceCount instances total.
|
||||
const instanceCount = 2500
|
||||
configInst, diags := eval.NewConfigInstance(b.Context(), &eval.ConfigCall{
|
||||
EvalContext: &eval.EvalContext{
|
||||
EvalContext: evalglue.EvalContextForTesting(b, &eval.EvalContext{
|
||||
Modules: eval.ModulesForTesting(map[addrs.ModuleSourceLocal]*configs.Module{
|
||||
addrs.ModuleSourceLocal("."): configs.ModuleFromStringForTesting(b, `
|
||||
# This test has two resources that each have a lot of instances
|
||||
@@ -112,7 +113,7 @@ func BenchmarkManyResourceInstances(b *testing.B) {
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
}),
|
||||
RootModuleSource: addrs.ModuleSourceLocal("."),
|
||||
InputValues: eval.InputValuesForTesting(map[string]cty.Value{
|
||||
"instance_count": cty.NumberIntVal(instanceCount),
|
||||
|
||||
Reference in New Issue
Block a user