(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func 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 | ` |
| 25 | function "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 | ` |
| 37 | function "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 | ` |
| 49 | function "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 | ` |
| 61 | function "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 | ` |
nothing calls this directly
no test coverage detected