(t *testing.T)
| 2041 | } |
| 2042 | |
| 2043 | func TestTemplateVersionVariables(t *testing.T) { |
| 2044 | t.Parallel() |
| 2045 | |
| 2046 | createEchoResponses := func(templateVariables []*proto.TemplateVariable) *echo.Responses { |
| 2047 | return &echo.Responses{ |
| 2048 | Parse: []*proto.Response{ |
| 2049 | { |
| 2050 | Type: &proto.Response_Parse{ |
| 2051 | Parse: &proto.ParseComplete{ |
| 2052 | TemplateVariables: templateVariables, |
| 2053 | }, |
| 2054 | }, |
| 2055 | }, |
| 2056 | }, |
| 2057 | ProvisionPlan: echo.PlanComplete, |
| 2058 | ProvisionApply: echo.ApplyComplete, |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | t.Run("Pass value for required variable", func(t *testing.T) { |
| 2063 | t.Parallel() |
| 2064 | |
| 2065 | templateVariables := []*proto.TemplateVariable{ |
| 2066 | { |
| 2067 | Name: "first_variable", |
| 2068 | Description: "This is the first variable", |
| 2069 | Type: "string", |
| 2070 | Required: true, |
| 2071 | }, |
| 2072 | } |
| 2073 | const firstVariableValue = "foobar" |
| 2074 | |
| 2075 | client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) |
| 2076 | user := coderdtest.CreateFirstUser(t, client) |
| 2077 | version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, |
| 2078 | createEchoResponses(templateVariables), |
| 2079 | func(ctvr *codersdk.CreateTemplateVersionRequest) { |
| 2080 | ctvr.UserVariableValues = []codersdk.VariableValue{ |
| 2081 | { |
| 2082 | Name: templateVariables[0].Name, |
| 2083 | Value: firstVariableValue, |
| 2084 | }, |
| 2085 | } |
| 2086 | }, |
| 2087 | ) |
| 2088 | templateVersion := coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 2089 | |
| 2090 | // As user passed the value for the first parameter, the job will succeed. |
| 2091 | require.Empty(t, templateVersion.Job.Error) |
| 2092 | |
| 2093 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) |
| 2094 | defer cancel() |
| 2095 | |
| 2096 | actualVariables, err := client.TemplateVersionVariables(ctx, templateVersion.ID) |
| 2097 | require.NoError(t, err) |
| 2098 | |
| 2099 | require.Len(t, actualVariables, 1) |
| 2100 | require.Equal(t, templateVariables[0].Name, actualVariables[0].Name) |
nothing calls this directly
no test coverage detected