Skip to content

Commit 8267098

Browse files
committed
check function descriptions directly
Now that we dynamically add scoped versions to the global functions we can't check the static Descriptions list. This should be OK since the function descriptions are taken directly from Descriptions list, and if any other scoped functions were added in the future, they may not be coming from the current global set of functions anyway.
1 parent 685e77b commit 8267098

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

internal/lang/funcs/descriptions.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
package funcs
55

6-
import "github.com/zclconf/go-cty/cty/function"
6+
import (
7+
"github.com/zclconf/go-cty/cty/function"
8+
)
79

810
type descriptionEntry struct {
911
// Description is a description for the function.

internal/lang/functions.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ func (s *Scope) Functions() map[string]function.Function {
178178
// namespaces that can serve as external extension points.
179179
s.funcs = make(map[string]function.Function, len(coreFuncs)*2)
180180
for name, fn := range coreFuncs {
181-
s.funcs[name] = funcs.WithDescription(name, fn)
181+
fn = funcs.WithDescription(name, fn)
182+
s.funcs[name] = fn
182183
s.funcs["core::"+name] = fn
183184
}
184185

internal/lang/functions_descriptions_test.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,14 @@ package lang
55

66
import (
77
"testing"
8-
9-
"github.com/hashicorp/terraform/internal/lang/funcs"
108
)
119

1210
func TestFunctionDescriptions(t *testing.T) {
1311
scope := &Scope{
1412
ConsoleMode: true,
1513
}
16-
// This will implicitly test the parameter description count since
17-
// WithNewDescriptions will panic if the number doesn't match.
18-
allFunctions := scope.Functions()
19-
20-
// plantimestamp isn't available with ConsoleMode: true
21-
expectedFunctionCount := len(funcs.DescriptionList) - 1
22-
23-
if len(allFunctions) != expectedFunctionCount {
24-
t.Errorf("DescriptionList length expected: %d, got %d", len(allFunctions), expectedFunctionCount)
25-
}
26-
27-
for name := range allFunctions {
28-
_, ok := funcs.DescriptionList[name]
29-
if !ok {
14+
for name, fn := range scope.Functions() {
15+
if fn.Description() == "" {
3016
t.Errorf("missing DescriptionList entry for function %q", name)
3117
}
3218
}

0 commit comments

Comments
 (0)