1
1
package provider_test
2
2
3
3
import (
4
+ "regexp"
4
5
"testing"
5
6
6
7
"github.com/coder/terraform-provider-coder/provider"
@@ -36,7 +37,6 @@ func TestAgent(t *testing.T) {
36
37
motd_file = "/etc/motd"
37
38
shutdown_script = "echo bye bye"
38
39
shutdown_script_timeout = 120
39
- startup_script_behavior = "blocking"
40
40
}
41
41
` ,
42
42
Check : func (state * terraform.State ) error {
@@ -58,7 +58,6 @@ func TestAgent(t *testing.T) {
58
58
"motd_file" ,
59
59
"shutdown_script" ,
60
60
"shutdown_script_timeout" ,
61
- "startup_script_behavior" ,
62
61
} {
63
62
value := resource .Primary .Attributes [key ]
64
63
t .Logf ("%q = %q" , key , value )
@@ -71,6 +70,97 @@ func TestAgent(t *testing.T) {
71
70
})
72
71
}
73
72
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
+
74
164
func TestAgent_Instance (t * testing.T ) {
75
165
t .Parallel ()
76
166
resource .Test (t , resource.TestCase {
0 commit comments