Skip to content

Commit f763469

Browse files
committed
Add test cases for startup script behavior
1 parent b6f0451 commit f763469

File tree

1 file changed

+92
-2
lines changed

1 file changed

+92
-2
lines changed

provider/agent_test.go

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provider_test
22

33
import (
4+
"regexp"
45
"testing"
56

67
"github.com/coder/terraform-provider-coder/provider"
@@ -36,7 +37,6 @@ func TestAgent(t *testing.T) {
3637
motd_file = "/etc/motd"
3738
shutdown_script = "echo bye bye"
3839
shutdown_script_timeout = 120
39-
startup_script_behavior = "blocking"
4040
}
4141
`,
4242
Check: func(state *terraform.State) error {
@@ -58,7 +58,6 @@ func TestAgent(t *testing.T) {
5858
"motd_file",
5959
"shutdown_script",
6060
"shutdown_script_timeout",
61-
"startup_script_behavior",
6261
} {
6362
value := resource.Primary.Attributes[key]
6463
t.Logf("%q = %q", key, value)
@@ -71,6 +70,97 @@ func TestAgent(t *testing.T) {
7170
})
7271
}
7372

73+
func TestAgent_StartupScriptBehavior(t *testing.T) {
74+
t.Parallel()
75+
76+
for _, tc := range []struct {
77+
Name string
78+
Config string
79+
ExpectError *regexp.Regexp
80+
Check func(state *terraform.ResourceState)
81+
}{
82+
{
83+
Name: "blocking",
84+
Config: `
85+
resource "coder_agent" "new" {
86+
os = "linux"
87+
arch = "amd64"
88+
startup_script_behavior = "blocking"
89+
}
90+
`,
91+
Check: func(state *terraform.ResourceState) {
92+
require.Equal(t, "blocking", state.Primary.Attributes["startup_script_behavior"])
93+
},
94+
},
95+
{
96+
Name: "non-blocking",
97+
Config: `
98+
resource "coder_agent" "new" {
99+
os = "linux"
100+
arch = "amd64"
101+
startup_script_behavior = "non-blocking"
102+
}
103+
`,
104+
Check: func(state *terraform.ResourceState) {
105+
require.Equal(t, "non-blocking", state.Primary.Attributes["startup_script_behavior"])
106+
},
107+
},
108+
{
109+
Name: "login_before_ready (deprecated)",
110+
Config: `
111+
resource "coder_agent" "new" {
112+
os = "linux"
113+
arch = "amd64"
114+
login_before_ready = false
115+
}
116+
`,
117+
Check: func(state *terraform.ResourceState) {
118+
require.Equal(t, "false", state.Primary.Attributes["login_before_ready"])
119+
// startup_script_behavior must be empty, this indicates that
120+
// login_before_ready should be used instead.
121+
require.Equal(t, "", state.Primary.Attributes["startup_script_behavior"])
122+
},
123+
},
124+
{
125+
Name: "no login_before_ready with startup_script_behavior",
126+
Config: `
127+
resource "coder_agent" "new" {
128+
os = "linux"
129+
arch = "amd64"
130+
login_before_ready = false
131+
startup_script_behavior = "blocking"
132+
}
133+
`,
134+
ExpectError: regexp.MustCompile("conflicts with"),
135+
},
136+
} {
137+
tc := tc
138+
t.Run(tc.Name, func(t *testing.T) {
139+
t.Parallel()
140+
resource.Test(t, resource.TestCase{
141+
Providers: map[string]*schema.Provider{
142+
"coder": provider.New(),
143+
},
144+
IsUnitTest: true,
145+
Steps: []resource.TestStep{{
146+
Config: tc.Config,
147+
ExpectError: tc.ExpectError,
148+
Check: func(state *terraform.State) error {
149+
require.Len(t, state.Modules, 1)
150+
require.Len(t, state.Modules[0].Resources, 1)
151+
resource := state.Modules[0].Resources["coder_agent.new"]
152+
require.NotNil(t, resource)
153+
if tc.Check != nil {
154+
tc.Check(resource)
155+
}
156+
return nil
157+
},
158+
}},
159+
})
160+
})
161+
}
162+
}
163+
74164
func TestAgent_Instance(t *testing.T) {
75165
t.Parallel()
76166
resource.Test(t, resource.TestCase{

0 commit comments

Comments
 (0)