|
4 | 4 | "reflect" |
5 | 5 | "testing" |
6 | 6 |
|
| 7 | + hcl "github.com/hashicorp/hcl/v2" |
7 | 8 | "github.com/stretchr/testify/require" |
8 | 9 | ) |
9 | 10 |
|
@@ -647,7 +648,7 @@ func TestHCLAttrsCapsuleType(t *testing.T) { |
647 | 648 | require.Equal(t, []string{"default", "key=path/to/key"}, stringify(c.Targets[0].SSH)) |
648 | 649 | } |
649 | 650 |
|
650 | | -func TestHCLAttrsCapsuleTypeVars(t *testing.T) { |
| 651 | +func TestHCLAttrsCapsuleType_ObjectVars(t *testing.T) { |
651 | 652 | dt := []byte(` |
652 | 653 | variable "foo" { |
653 | 654 | default = "bar" |
@@ -716,6 +717,44 @@ func TestHCLAttrsCapsuleTypeVars(t *testing.T) { |
716 | 717 | require.Equal(t, []string{"id=oci,src=/local/secret"}, stringify(web.Secrets)) |
717 | 718 | } |
718 | 719 |
|
| 720 | +func TestHCLAttrsCapsuleType_MissingVars(t *testing.T) { |
| 721 | + dt := []byte(` |
| 722 | + target "app" { |
| 723 | + attest = [ |
| 724 | + "type=sbom,disabled=${SBOM}", |
| 725 | + ] |
| 726 | +
|
| 727 | + cache-from = [ |
| 728 | + { type = "registry", ref = "user/app:${FOO1}" }, |
| 729 | + "type=local,src=path/to/cache:${FOO2}", |
| 730 | + ] |
| 731 | +
|
| 732 | + cache-to = [ |
| 733 | + { type = "local", dest = "path/to/${BAR}" }, |
| 734 | + ] |
| 735 | +
|
| 736 | + output = [ |
| 737 | + { type = "oci", dest = "../${OUTPUT}.tar" }, |
| 738 | + ] |
| 739 | +
|
| 740 | + secret = [ |
| 741 | + { id = "mysecret", src = "/local/${SECRET}" }, |
| 742 | + ] |
| 743 | +
|
| 744 | + ssh = [ |
| 745 | + { id = "key", paths = ["path/to/${SSH_KEY}"] }, |
| 746 | + ] |
| 747 | + } |
| 748 | + `) |
| 749 | + |
| 750 | + var diags hcl.Diagnostics |
| 751 | + _, err := ParseFile(dt, "docker-bake.hcl") |
| 752 | + require.ErrorAs(t, err, &diags) |
| 753 | + |
| 754 | + // One extra error because the value is unknown. |
| 755 | + require.Len(t, diags, 8) |
| 756 | +} |
| 757 | + |
719 | 758 | func TestHCLMultiFileAttrs(t *testing.T) { |
720 | 759 | dt := []byte(` |
721 | 760 | variable "FOO" { |
|
0 commit comments