Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add open_in option to coder_app #321

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. " +
defelmnq marked this conversation as resolved.
Show resolved Hide resolved
"`\"slim-window\"` opens a fresh browser window with slim navigation options.",
defelmnq marked this conversation as resolved.
Show resolved Hide resolved
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",
defelmnq marked this conversation as resolved.
Show resolved Hide resolved
}, {
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}}
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
Loading