Skip to content

Commit 3d5fc0b

Browse files
committed
work on tests
1 parent 6ca152d commit 3d5fc0b

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed

docs/resources/app.md

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ resource "coder_app" "vim" {
6565
- `healthcheck` (Block Set, Max: 1) HTTP health checking to determine the application readiness. (see [below for nested schema](#nestedblock--healthcheck))
6666
- `hidden` (Boolean) Determines if the app is visible in the UI (minimum Coder version: v2.16).
6767
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons here: https://github.com/coder/coder/tree/main/site/static/icon. Use a built-in icon with `"${data.coder_workspace.me.access_url}/icon/<path>"`.
68+
- `open_in` (String) Determines where the app will be opened. Valid values are `"tab"`, `"window"`, and `"slim-window" (default)`. `"tab"` opens in a new tab in the same browser window. `"window"` opens a fresh browser window with navigation options. `"slim-window"` opens a fresh browser window with slim navigation options.
6869
- `order` (Number) The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order).
6970
- `share` (String) Determines the level which the application is shared at. Valid levels are `"owner"` (default), `"authenticated"` and `"public"`. Level `"owner"` disables sharing on the app, so only the workspace owner can access it. Level `"authenticated"` shares the app with all authenticated users. Level `"public"` shares it with any user, including unauthenticated users. Permitted application sharing levels can be configured site-wide via a flag on `coder server` (Enterprise only).
7071
- `subdomain` (Boolean) Determines whether the app will be accessed via it's own subdomain or whether it will be accessed via a path on Coder. If wildcards have not been setup by the administrator then apps with `subdomain` set to `true` will not be accessible. Defaults to `false`.

integration/coder-app-open-in/main.tf

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
local = {
7+
source = "hashicorp/local"
8+
}
9+
}
10+
}
11+
12+
data "coder_workspace" "me" {}
13+
14+
resource "coder_agent" "dev" {
15+
os = "linux"
16+
arch = "amd64"
17+
dir = "/workspace"
18+
}
19+
20+
resource "coder_app" "window" {
21+
agent_id = coder_agent.dev.id
22+
slug = "window"
23+
share = "owner"
24+
open_in = "window"
25+
}
26+
27+
resource "coder_app" "slim-window" {
28+
agent_id = coder_agent.dev.id
29+
slug = "slim-window"
30+
share = "owner"
31+
open_in = "slim-window"
32+
}
33+
34+
resource "coder_app" "defaulted" {
35+
agent_id = coder_agent.dev.id
36+
slug = "defaulted"
37+
share = "owner"
38+
}
39+
40+
locals {
41+
# NOTE: these must all be strings in the output
42+
output = {
43+
"coder_app.window.open_in" = tostring(coder_app.window.open_in)
44+
"coder_app.slim-window.open_in" = tostring(coder_app.slim-window.open_in)
45+
"coder_app.defaulted.open_in" = tostring(coder_app.defaulted.open_in)
46+
}
47+
}
48+
49+
variable "output_path" {
50+
type = string
51+
}
52+
53+
resource "local_file" "output" {
54+
filename = var.output_path
55+
content = jsonencode(local.output)
56+
}
57+
58+
output "output" {
59+
value = local.output
60+
sensitive = true
61+
}
62+

integration/integration_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ func TestIntegration(t *testing.T) {
143143
"workspace_owner.login_type": `password`,
144144
},
145145
},
146+
{
147+
name: "workspace-with-open-in",
148+
minVersion: "v2.19.0",
149+
expectedOutput: map[string]string{
150+
"coder_app.window.open_in": "window",
151+
"coder_app.slim-window.open_in": "slim-window",
152+
"coder_app.defaulted.open_in": "slim-window",
153+
},
154+
},
146155
{
147156
name: "coder-app-hidden",
148157
minVersion: "v0.0.0",

provider/app_test.go

+100
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,106 @@ func TestApp(t *testing.T) {
246246
}
247247
})
248248

249+
t.Run("OpenIn", func(t *testing.T) {
250+
t.Parallel()
251+
252+
cases := []struct {
253+
name string
254+
value string
255+
expectValue string
256+
expectError *regexp.Regexp
257+
}{
258+
{
259+
name: "default",
260+
value: "", // default
261+
expectValue: "slim-window",
262+
},
263+
{
264+
name: "InvalidValue",
265+
value: "nonsense",
266+
expectError: regexp.MustCompile(`invalid "coder_app" open_in value, must be one of "tab", "window", "slim-window": "nonsense"`),
267+
},
268+
{
269+
name: "ExplicitWindow",
270+
value: "window",
271+
expectValue: "window",
272+
},
273+
{
274+
name: "ExplicitSlimWindow",
275+
value: "slim-window",
276+
expectValue: "slim-window",
277+
},
278+
{
279+
name: "ExplicitTab",
280+
value: "tab",
281+
expectValue: "tab",
282+
},
283+
}
284+
285+
for _, c := range cases {
286+
c := c
287+
288+
t.Run(c.name, func(t *testing.T) {
289+
t.Parallel()
290+
291+
config := `
292+
provider "coder" {
293+
}
294+
resource "coder_agent" "dev" {
295+
os = "linux"
296+
arch = "amd64"
297+
}
298+
resource "coder_app" "code-server" {
299+
agent_id = coder_agent.dev.id
300+
slug = "code-server"
301+
display_name = "code-server"
302+
icon = "builtin:vim"
303+
url = "http://localhost:13337"
304+
healthcheck {
305+
url = "http://localhost:13337/healthz"
306+
interval = 5
307+
threshold = 6
308+
}`
309+
310+
if c.value != "" {
311+
config += fmt.Sprintf(`
312+
open_in = %q
313+
`, c.value)
314+
}
315+
316+
config += `
317+
}
318+
`
319+
320+
checkFn := func(state *terraform.State) error {
321+
require.Len(t, state.Modules, 1)
322+
require.Len(t, state.Modules[0].Resources, 2)
323+
resource := state.Modules[0].Resources["coder_app.code-server"]
324+
require.NotNil(t, resource)
325+
326+
// Read share and ensure it matches the expected
327+
// value.
328+
value := resource.Primary.Attributes["open_in"]
329+
require.Equal(t, c.expectValue, value)
330+
return nil
331+
}
332+
if c.expectError != nil {
333+
checkFn = nil
334+
}
335+
336+
resource.Test(t, resource.TestCase{
337+
ProviderFactories: coderFactory(),
338+
IsUnitTest: true,
339+
Steps: []resource.TestStep{{
340+
Config: config,
341+
Check: checkFn,
342+
ExpectError: c.expectError,
343+
}},
344+
})
345+
})
346+
}
347+
})
348+
249349
t.Run("Hidden", func(t *testing.T) {
250350
t.Parallel()
251351

0 commit comments

Comments
 (0)