TestTemplateVersionPresetValidation validates that presets with prebuilds are validated dynamically. A preset that enables a conditional parameter but doesn't provide the required value for the newly-visible parameter should fail validation during template version import. Scenario: - Parameter A (u
(t *testing.T)
| 789 | // values. ValidatePrebuilds catches this by evaluating with the preset's |
| 790 | // parameter values. |
| 791 | func TestTemplateVersionPresetValidation(t *testing.T) { |
| 792 | t.Parallel() |
| 793 | |
| 794 | store, ps := dbtestutil.NewDB(t) |
| 795 | client := coderdtest.New(t, &coderdtest.Options{ |
| 796 | Database: store, |
| 797 | Pubsub: ps, |
| 798 | }) |
| 799 | owner := coderdtest.CreateFirstUser(t, client) |
| 800 | templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin()) |
| 801 | |
| 802 | ctx := testutil.Context(t, testutil.WaitShort) |
| 803 | |
| 804 | tf := func(valid bool, prebuildCount int) string { |
| 805 | customImageURL := "" |
| 806 | if valid { |
| 807 | customImageURL = `custom_image_url = "ghcr.io/coder/example:latest"` |
| 808 | } |
| 809 | return fmt.Sprintf(` |
| 810 | terraform { |
| 811 | required_providers { |
| 812 | coder = { |
| 813 | source = "coder/coder" |
| 814 | version = "2.8.0" |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | data "coder_parameter" "use_custom_image" { |
| 820 | name = "use_custom_image" |
| 821 | type = "bool" |
| 822 | default = "false" |
| 823 | } |
| 824 | |
| 825 | data "coder_parameter" "custom_image_url" { |
| 826 | count = data.coder_parameter.use_custom_image.value == "true" ? 1 : 0 |
| 827 | name = "custom_image_url" |
| 828 | type = "string" |
| 829 | # No default - required when shown |
| 830 | } |
| 831 | |
| 832 | data "coder_workspace_preset" "invalid" { |
| 833 | name = "Invalid Preset" |
| 834 | parameters = { |
| 835 | "use_custom_image" = "true" |
| 836 | %s |
| 837 | } |
| 838 | prebuilds { |
| 839 | instances = %d |
| 840 | } |
| 841 | } |
| 842 | `, customImageURL, prebuildCount) |
| 843 | } |
| 844 | |
| 845 | tarFile := testutil.CreateTar(t, map[string]string{ |
| 846 | `main.tf`: tf(false, 1), |
| 847 | }) |
| 848 |
nothing calls this directly
no test coverage detected