TestExpressionValue_Diags asserts that Value() returns diagnostics from nested evaluations for complex objects (e.g. ObjectVal, ArrayVal)
(t *testing.T)
| 1419 | // TestExpressionValue_Diags asserts that Value() returns diagnostics |
| 1420 | // from nested evaluations for complex objects (e.g. ObjectVal, ArrayVal) |
| 1421 | func TestExpressionValue_Diags(t *testing.T) { |
| 1422 | cases := []struct { |
| 1423 | name string |
| 1424 | src string |
| 1425 | expected cty.Value |
| 1426 | error string |
| 1427 | }{ |
| 1428 | { |
| 1429 | name: "string: happy", |
| 1430 | src: `{"v": "happy ${VAR1}"}`, |
| 1431 | expected: cty.StringVal("happy case"), |
| 1432 | }, |
| 1433 | { |
| 1434 | name: "string: unhappy", |
| 1435 | src: `{"v": "happy ${UNKNOWN}"}`, |
| 1436 | expected: cty.UnknownVal(cty.String).RefineNotNull(), |
| 1437 | error: "Unknown variable", |
| 1438 | }, |
| 1439 | { |
| 1440 | name: "object_val: happy", |
| 1441 | src: `{"v": {"key": "happy ${VAR1}"}}`, |
| 1442 | expected: cty.ObjectVal(map[string]cty.Value{ |
| 1443 | "key": cty.StringVal("happy case"), |
| 1444 | }), |
| 1445 | }, |
| 1446 | { |
| 1447 | name: "object_val: unhappy", |
| 1448 | src: `{"v": {"key": "happy ${UNKNOWN}"}}`, |
| 1449 | expected: cty.ObjectVal(map[string]cty.Value{ |
| 1450 | "key": cty.UnknownVal(cty.String).RefineNotNull(), |
| 1451 | }), |
| 1452 | error: "Unknown variable", |
| 1453 | }, |
| 1454 | { |
| 1455 | name: "object_key: happy", |
| 1456 | src: `{"v": {"happy ${VAR1}": "val"}}`, |
| 1457 | expected: cty.ObjectVal(map[string]cty.Value{ |
| 1458 | "happy case": cty.StringVal("val"), |
| 1459 | }), |
| 1460 | }, |
| 1461 | { |
| 1462 | name: "object_key: unhappy", |
| 1463 | src: `{"v": {"happy ${UNKNOWN}": "val"}}`, |
| 1464 | expected: cty.DynamicVal, |
| 1465 | error: "Unknown variable", |
| 1466 | }, |
| 1467 | { |
| 1468 | name: "array: happy", |
| 1469 | src: `{"v": ["happy ${VAR1}"]}`, |
| 1470 | expected: cty.TupleVal([]cty.Value{cty.StringVal("happy case")}), |
| 1471 | }, |
| 1472 | { |
| 1473 | name: "array: unhappy", |
| 1474 | src: `{"v": ["happy ${UNKNOWN}"]}`, |
| 1475 | expected: cty.TupleVal([]cty.Value{cty.UnknownVal(cty.String).RefineNotNull()}), |
| 1476 | error: "Unknown variable", |
| 1477 | }, |
| 1478 | } |
nothing calls this directly
no test coverage detected