MCPcopy
hub / github.com/hashicorp/hcl / TestDecodeUserFunctions

Function TestDecodeUserFunctions

ext/userfunc/decode_test.go:15–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestDecodeUserFunctions(t *testing.T) {
16 tests := []struct {
17 src string
18 testExpr string
19 baseCtx *hcl.EvalContext
20 want cty.Value
21 diagCount int
22 }{
23 {
24 `
25function "greet" {
26 params = [name]
27 result = "Hello, ${name}."
28}
29`,
30 `greet("Ermintrude")`,
31 nil,
32 cty.StringVal("Hello, Ermintrude."),
33 0,
34 },
35 {
36 `
37function "greet" {
38 params = [name]
39 result = "Hello, ${name}."
40}
41`,
42 `greet()`,
43 nil,
44 cty.DynamicVal,
45 1, // missing value for "name"
46 },
47 {
48 `
49function "greet" {
50 params = [name]
51 result = "Hello, ${name}."
52}
53`,
54 `greet("Ermintrude", "extra")`,
55 nil,
56 cty.DynamicVal,
57 1, // too many arguments
58 },
59 {
60 `
61function "add" {
62 params = [a, b]
63 result = a + b
64}
65`,
66 `add(1, 5)`,
67 nil,
68 cty.NumberIntVal(6),
69 0,
70 },
71 {
72 `

Callers

nothing calls this directly

Calls 5

ParseConfigFunction · 0.92
ParseExpressionFunction · 0.92
decodeUserFunctionsFunction · 0.85
RunMethod · 0.80
ValueMethod · 0.65

Tested by

no test coverage detected