Skip to content

Commit

Permalink
add open_in option to coder_app
Browse files Browse the repository at this point in the history
  • Loading branch information
defelmnq committed Dec 4, 2024
1 parent c9dbd6f commit 6ca152d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,28 @@ func appResource() *schema.Resource {
ForceNew: true,
Optional: true,
},
"open_in": {
Type: schema.TypeString,
Description: "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.",
ForceNew: true,
Optional: true,
Default: "slim-window",
ValidateDiagFunc: func(val interface{}, c cty.Path) diag.Diagnostics {
valStr, ok := val.(string)
if !ok {
return diag.Errorf("expected string, got %T", val)
}

switch valStr {
case "tab", "window", "slim-window":
return nil
}

return diag.Errorf(`invalid "coder_app" open_in value, must be one of "tab", "window", "slim-window": %q`, valStr)
},
},
},
}
}
11 changes: 11 additions & 0 deletions provider/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestApp(t *testing.T) {
}
order = 4
hidden = false
open_in = "slim-window"
}
`,
Check: func(state *terraform.State) error {
Expand All @@ -64,6 +65,7 @@ func TestApp(t *testing.T) {
"healthcheck.0.threshold",
"order",
"hidden",
"open_in",
} {
value := resource.Primary.Attributes[key]
t.Logf("%q = %q", key, value)
Expand Down Expand Up @@ -98,6 +100,7 @@ func TestApp(t *testing.T) {
display_name = "Testing"
url = "https://google.com"
external = true
open_in = "slim-window"
}
`,
external: true,
Expand All @@ -116,6 +119,7 @@ func TestApp(t *testing.T) {
url = "https://google.com"
external = true
subdomain = true
open_in = "slim-window"
}
`,
expectError: regexp.MustCompile("conflicts with subdomain"),
Expand Down Expand Up @@ -209,6 +213,7 @@ func TestApp(t *testing.T) {
interval = 5
threshold = 6
}
open_in = "slim-window"
}
`, sharingLine)

Expand Down Expand Up @@ -248,6 +253,7 @@ func TestApp(t *testing.T) {
name string
config string
hidden bool
openIn string
}{{
name: "Is Hidden",
config: `
Expand All @@ -263,9 +269,11 @@ func TestApp(t *testing.T) {
url = "https://google.com"
external = true
hidden = true
open_in = "slim-window"
}
`,
hidden: true,
openIn: "slim-window",
}, {
name: "Is Not Hidden",
config: `
Expand All @@ -281,9 +289,11 @@ func TestApp(t *testing.T) {
url = "https://google.com"
external = true
hidden = false
open_in = "window"
}
`,
hidden: false,
openIn: "window",
}}
for _, tc := range cases {
tc := tc
Expand All @@ -300,6 +310,7 @@ func TestApp(t *testing.T) {
resource := state.Modules[0].Resources["coder_app.test"]
require.NotNil(t, resource)
require.Equal(t, strconv.FormatBool(tc.hidden), resource.Primary.Attributes["hidden"])
require.Equal(t, tc.openIn, resource.Primary.Attributes["open_in"])
return nil
},
ExpectError: nil,
Expand Down

0 comments on commit 6ca152d

Please sign in to comment.