-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add default_apps
field to coder_agent
resource
#147
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
Changes from all commits
f14f186
6354863
c526179
41f4ebd
ce6fd70
018a016
2486658
3d29895
6daeca7
aafdee4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
package provider_test | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/coder/terraform-provider-coder/provider" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/terraform-provider-coder/provider" | ||
) | ||
|
||
func TestAgent(t *testing.T) { | ||
|
@@ -247,3 +249,181 @@ func TestAgent_Metadata(t *testing.T) { | |
}}, | ||
}) | ||
} | ||
|
||
func TestAgent_DisplayApps(t *testing.T) { | ||
t.Parallel() | ||
t.Run("OK", func(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
Providers: map[string]*schema.Provider{ | ||
"coder": provider.New(), | ||
}, | ||
IsUnitTest: true, | ||
Steps: []resource.TestStep{{ | ||
// Test the fields with non-default values. | ||
Config: ` | ||
sreya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
provider "coder" { | ||
url = "https://example.com" | ||
} | ||
resource "coder_agent" "dev" { | ||
os = "linux" | ||
arch = "amd64" | ||
display_apps { | ||
vscode = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need an extra test case to check .tf with only a few apps selected:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since they all have default values I tested that specifying their non-defaults (in |
||
vscode_insiders = true | ||
web_terminal = false | ||
port_forwarding_helper = false | ||
ssh_helper = false | ||
} | ||
} | ||
`, | ||
Check: func(state *terraform.State) error { | ||
require.Len(t, state.Modules, 1) | ||
require.Len(t, state.Modules[0].Resources, 1) | ||
|
||
resource := state.Modules[0].Resources["coder_agent.dev"] | ||
require.NotNil(t, resource) | ||
|
||
t.Logf("resource: %v", resource.Primary.Attributes) | ||
|
||
for _, app := range []string{ | ||
"web_terminal", | ||
"vscode_insiders", | ||
"vscode", | ||
"port_forwarding_helper", | ||
"ssh_helper", | ||
} { | ||
key := fmt.Sprintf("display_apps.0.%s", app) | ||
if app == "vscode_insiders" { | ||
require.Equal(t, "true", resource.Primary.Attributes[key]) | ||
} else { | ||
require.Equal(t, "false", resource.Primary.Attributes[key]) | ||
} | ||
} | ||
return nil | ||
}, | ||
}}, | ||
}) | ||
}) | ||
|
||
t.Run("Subset", func(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
Providers: map[string]*schema.Provider{ | ||
"coder": provider.New(), | ||
}, | ||
IsUnitTest: true, | ||
Steps: []resource.TestStep{{ | ||
// Test the fields with non-default values. | ||
Config: ` | ||
provider "coder" { | ||
url = "https://example.com" | ||
} | ||
resource "coder_agent" "dev" { | ||
os = "linux" | ||
arch = "amd64" | ||
display_apps { | ||
vscode_insiders = true | ||
web_terminal = true | ||
} | ||
} | ||
`, | ||
Check: func(state *terraform.State) error { | ||
require.Len(t, state.Modules, 1) | ||
require.Len(t, state.Modules[0].Resources, 1) | ||
|
||
resource := state.Modules[0].Resources["coder_agent.dev"] | ||
require.NotNil(t, resource) | ||
|
||
t.Logf("resource: %v", resource.Primary.Attributes) | ||
|
||
for _, app := range []string{ | ||
"web_terminal", | ||
"vscode_insiders", | ||
"vscode", | ||
"port_forwarding_helper", | ||
"ssh_helper", | ||
} { | ||
key := fmt.Sprintf("display_apps.0.%s", app) | ||
require.Equal(t, "true", resource.Primary.Attributes[key]) | ||
} | ||
return nil | ||
}, | ||
}}, | ||
}) | ||
}) | ||
|
||
// Assert all the defaults are set correctly. | ||
t.Run("Omitted", func(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
Providers: map[string]*schema.Provider{ | ||
"coder": provider.New(), | ||
}, | ||
IsUnitTest: true, | ||
Steps: []resource.TestStep{{ | ||
Config: ` | ||
provider "coder" { | ||
url = "https://example.com" | ||
} | ||
resource "coder_agent" "dev" { | ||
os = "linux" | ||
arch = "amd64" | ||
} | ||
`, | ||
Check: func(state *terraform.State) error { | ||
require.Len(t, state.Modules, 1) | ||
require.Len(t, state.Modules[0].Resources, 1) | ||
|
||
resource := state.Modules[0].Resources["coder_agent.dev"] | ||
require.NotNil(t, resource) | ||
|
||
t.Logf("resource: %v", resource.Primary.Attributes) | ||
|
||
for _, app := range []string{ | ||
"web_terminal", | ||
"vscode_insiders", | ||
"vscode", | ||
"port_forwarding_helper", | ||
"ssh_helper", | ||
} { | ||
key := fmt.Sprintf("display_apps.0.%s", app) | ||
if app == "vscode_insiders" { | ||
require.Equal(t, "false", resource.Primary.Attributes[key]) | ||
} else { | ||
require.Equal(t, "true", resource.Primary.Attributes[key]) | ||
} | ||
} | ||
return nil | ||
}, | ||
}}, | ||
}) | ||
}) | ||
|
||
t.Run("InvalidApp", func(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
Providers: map[string]*schema.Provider{ | ||
"coder": provider.New(), | ||
}, | ||
IsUnitTest: true, | ||
Steps: []resource.TestStep{{ | ||
// Test the fields with non-default values. | ||
Config: ` | ||
provider "coder" { | ||
url = "https://example.com" | ||
} | ||
resource "coder_agent" "dev" { | ||
os = "linux" | ||
arch = "amd64" | ||
display_apps { | ||
fake_app = false | ||
vscode_insiders = true | ||
web_terminal = false | ||
port_forwarding_helper = false | ||
ssh_helper = false | ||
} | ||
} | ||
`, | ||
ExpectError: regexp.MustCompile(`An argument named "fake_app" is not expected here.`), | ||
}}, | ||
}) | ||
}) | ||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.