Skip to content

Commit e6f35c6

Browse files
committed
add integration tests
1 parent 1a717dd commit e6f35c6

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

integration/integration_test.go

+32-13
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,27 @@ func TestIntegration(t *testing.T) {
7373
name: "test-data-source",
7474
minVersion: "v0.0.0",
7575
expectedOutput: map[string]string{
76-
"provisioner.arch": runtime.GOARCH,
77-
"provisioner.id": `[a-zA-Z0-9-]+`,
78-
"provisioner.os": runtime.GOOS,
79-
"workspace.access_port": `\d+`,
80-
"workspace.access_url": `https?://\D+:\d+`,
81-
"workspace.id": `[a-zA-z0-9-]+`,
82-
"workspace.name": `test-data-source`,
83-
"workspace.start_count": `1`,
84-
"workspace.template_id": `[a-zA-Z0-9-]+`,
85-
"workspace.template_name": `test-data-source`,
86-
"workspace.template_version": `.+`,
87-
"workspace.transition": `start`,
76+
"provisioner.arch": runtime.GOARCH,
77+
"provisioner.id": `[a-zA-Z0-9-]+`,
78+
"provisioner.os": runtime.GOOS,
79+
"workspace.access_port": `\d+`,
80+
"workspace.access_url": `https?://\D+:\d+`,
81+
"workspace.id": `[a-zA-z0-9-]+`,
82+
"workspace.name": `test-data-source`,
83+
"workspace.start_count": `1`,
84+
"workspace.template_id": `[a-zA-Z0-9-]+`,
85+
"workspace.template_name": `test-data-source`,
86+
"workspace.template_version": `.+`,
87+
"workspace.transition": `start`,
88+
"workspace_parameter.name": `param`,
89+
"workspace_parameter.description": `param description`,
90+
// TODO (sasswart): the cli doesn't support presets yet.
91+
// once it does, the value for workspace_parameter.value
92+
// will be the preset value.
93+
"workspace_parameter.value": `param value`,
94+
"workspace_parameter.icon": `param icon`,
95+
"workspace_preset.name": `preset`,
96+
"workspace_preset.parameters.param": `preset param value`,
8897
},
8998
},
9099
{
@@ -179,8 +188,18 @@ func TestIntegration(t *testing.T) {
179188
}
180189
_, rc := execContainer(ctx, t, ctrID, fmt.Sprintf(`coder templates %s %s --directory /src/integration/%s --var output_path=/tmp/%s.json --yes`, templateCreateCmd, tt.name, tt.name, tt.name))
181190
require.Equal(t, 0, rc)
191+
192+
// Check if parameters.yaml exists
193+
_, rc = execContainer(ctx, t, ctrID, fmt.Sprintf(`stat /src/integration/%s/parameters.yaml 2>/dev/null > /dev/null`, tt.name))
194+
hasParameters := rc == 0
195+
var includeParameters string
196+
if hasParameters {
197+
// If it exists, include it in the create command
198+
includeParameters = fmt.Sprintf(`--rich-parameter-file /src/integration/%s/parameters.yaml`, tt.name)
199+
}
200+
182201
// Create a workspace
183-
_, rc = execContainer(ctx, t, ctrID, fmt.Sprintf(`coder create %s -t %s --yes`, tt.name, tt.name))
202+
_, rc = execContainer(ctx, t, ctrID, fmt.Sprintf(`coder create %s -t %s %s --yes`, tt.name, tt.name, includeParameters))
184203
require.Equal(t, 0, rc)
185204
// Fetch the output created by the template
186205
out, rc := execContainer(ctx, t, ctrID, fmt.Sprintf(`cat /tmp/%s.json`, tt.name))

integration/test-data-source/main.tf

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ terraform {
1414
data "coder_provisioner" "me" {}
1515
data "coder_workspace" "me" {}
1616
data "coder_workspace_owner" "me" {}
17+
data "coder_parameter" "param" {
18+
name = "param"
19+
description = "param description"
20+
icon = "param icon"
21+
}
22+
data "coder_workspace_preset" "preset" {
23+
name = "preset"
24+
parameters = {
25+
(data.coder_parameter.param.name) = "preset param value"
26+
}
27+
}
1728

1829
locals {
1930
# NOTE: these must all be strings in the output
@@ -30,6 +41,12 @@ locals {
3041
"workspace.template_name" : data.coder_workspace.me.template_name,
3142
"workspace.template_version" : data.coder_workspace.me.template_version,
3243
"workspace.transition" : data.coder_workspace.me.transition,
44+
"workspace_parameter.name" : data.coder_parameter.param.name,
45+
"workspace_parameter.description" : data.coder_parameter.param.description,
46+
"workspace_parameter.value" : data.coder_parameter.param.value,
47+
"workspace_parameter.icon" : data.coder_parameter.param.icon,
48+
"workspace_preset.name" : data.coder_workspace_preset.preset.name,
49+
"workspace_preset.parameters.param" : data.coder_workspace_preset.preset.parameters.param,
3350
}
3451
}
3552

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
param: "param value"

0 commit comments

Comments
 (0)