|
1 | 1 | package provider_test
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "regexp"
|
| 6 | + "strings" |
5 | 7 | "testing"
|
6 | 8 |
|
7 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
@@ -816,3 +818,43 @@ func TestValueValidatesType(t *testing.T) {
|
816 | 818 | })
|
817 | 819 | }
|
818 | 820 | }
|
| 821 | + |
| 822 | +func TestParameterWithManyOptions(t *testing.T) { |
| 823 | + t.Parallel() |
| 824 | + |
| 825 | + const maxItemsInTest = 1024 |
| 826 | + |
| 827 | + var options strings.Builder |
| 828 | + for i := 0; i < maxItemsInTest; i++ { |
| 829 | + _, _ = options.WriteString(fmt.Sprintf(`option { |
| 830 | + name = "%d" |
| 831 | + value = "%d" |
| 832 | + } |
| 833 | +`, i, i)) |
| 834 | + } |
| 835 | + |
| 836 | + resource.Test(t, resource.TestCase{ |
| 837 | + ProviderFactories: coderFactory(), |
| 838 | + IsUnitTest: true, |
| 839 | + Steps: []resource.TestStep{{ |
| 840 | + Config: fmt.Sprintf(`data "coder_parameter" "region" { |
| 841 | + name = "Region" |
| 842 | + type = "string" |
| 843 | + %s |
| 844 | + }`, options.String()), |
| 845 | + Check: func(state *terraform.State) error { |
| 846 | + require.Len(t, state.Modules, 1) |
| 847 | + require.Len(t, state.Modules[0].Resources, 1) |
| 848 | + param := state.Modules[0].Resources["data.coder_parameter.region"] |
| 849 | + |
| 850 | + for i := 0; i < maxItemsInTest; i++ { |
| 851 | + name, _ := param.Primary.Attributes[fmt.Sprintf("option.%d.name", i)] |
| 852 | + value, _ := param.Primary.Attributes[fmt.Sprintf("option.%d.value", i)] |
| 853 | + require.Equal(t, fmt.Sprintf("%d", i), name) |
| 854 | + require.Equal(t, fmt.Sprintf("%d", i), value) |
| 855 | + } |
| 856 | + return nil |
| 857 | + }, |
| 858 | + }}, |
| 859 | + }) |
| 860 | +} |
0 commit comments