(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestParse(t *testing.T) { |
| 18 | t.Parallel() |
| 19 | |
| 20 | cwd, err := os.Getwd() |
| 21 | require.NoError(t, err) |
| 22 | |
| 23 | ctx, api := setupProvisioner(t, &provisionerServeOptions{ |
| 24 | // Fake all actual terraform, since parse doesn't need it. |
| 25 | binaryPath: filepath.Join(cwd, "testdata", "timings-aggregation", "fake-terraform.sh"), |
| 26 | }) |
| 27 | |
| 28 | testCases := []struct { |
| 29 | Name string |
| 30 | Files map[string]string |
| 31 | Response *proto.ParseComplete |
| 32 | ParseErrorContains string |
| 33 | }{ |
| 34 | { |
| 35 | Name: "single-variable", |
| 36 | Files: map[string]string{ |
| 37 | "main.tf": `variable "A" { |
| 38 | description = "Testing!" |
| 39 | }`, |
| 40 | }, |
| 41 | Response: &proto.ParseComplete{ |
| 42 | TemplateVariables: []*proto.TemplateVariable{ |
| 43 | { |
| 44 | Name: "A", |
| 45 | Description: "Testing!", |
| 46 | Required: true, |
| 47 | }, |
| 48 | }, |
| 49 | }, |
| 50 | }, |
| 51 | { |
| 52 | Name: "default-variable-value", |
| 53 | Files: map[string]string{ |
| 54 | "main.tf": `variable "A" { |
| 55 | default = "wow" |
| 56 | }`, |
| 57 | }, |
| 58 | Response: &proto.ParseComplete{ |
| 59 | TemplateVariables: []*proto.TemplateVariable{ |
| 60 | { |
| 61 | Name: "A", |
| 62 | DefaultValue: "wow", |
| 63 | }, |
| 64 | }, |
| 65 | }, |
| 66 | }, |
| 67 | { |
| 68 | Name: "variable-validation", |
| 69 | Files: map[string]string{ |
| 70 | "main.tf": `variable "A" { |
| 71 | validation { |
| 72 | condition = var.A == "value" |
| 73 | error_message = "A must be 'value'" |
| 74 | } |
nothing calls this directly
no test coverage detected