@@ -45,7 +45,7 @@ func TestDataSourceMetadataSchemaAndConfigure(t *testing.T) {
4545
4646 var schema datasource.SchemaResponse
4747 ds .Schema (context .Background (), datasource.SchemaRequest {}, & schema )
48- for _ , name := range []string {"id" , "name" , "project_id" , "size" , "profile_id" , "extension_ids" , "proxy_id" , "headless" , "kiosk_mode" , "stealth" } {
48+ for _ , name := range []string {"id" , "name" , "project_id" , "size" , "profile_id" , "extension_ids" , "proxy_id" , "headless" , "kiosk_mode" , "stealth" , "start_url" , "timeout_seconds" , "fill_rate_per_minute" } {
4949 if _ , ok := schema .Schema .Attributes [name ]; ! ok {
5050 t .Fatalf ("schema missing %s" , name )
5151 }
@@ -143,7 +143,10 @@ func TestReadSetsTerraformState(t *testing.T) {
143143 "proxy_id":"proxy-1",
144144 "headless":true,
145145 "kiosk_mode":false,
146- "stealth":true
146+ "stealth":true,
147+ "start_url":"chrome://newtab",
148+ "timeout_seconds":10,
149+ "fill_rate_per_minute":0
147150 }
148151 }` ), nil
149152 },
@@ -180,6 +183,56 @@ func TestReadSetsTerraformState(t *testing.T) {
180183 if state .ProxyID .ValueString () != "proxy-1" || ! state .Headless .ValueBool () || state .KioskMode .IsNull () || state .KioskMode .ValueBool () || ! state .Stealth .ValueBool () {
181184 t .Fatalf ("launch state = %#v" , state )
182185 }
186+ if state .StartURL .ValueString () != "chrome://newtab" || state .TimeoutSeconds .ValueInt64 () != 10 || state .FillRatePerMinute .IsNull () || state .FillRatePerMinute .IsUnknown () || state .FillRatePerMinute .ValueInt64 () != 0 {
187+ t .Fatalf ("warmup state = %#v" , state )
188+ }
189+ }
190+
191+ func TestFlattenBrowserPoolWarmupConfigurationBoundaries (t * testing.T ) {
192+ t .Parallel ()
193+
194+ omitted , diags := flattenBrowserPool (* browserPoolFromJSON (`{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1}}` ))
195+ if diags .HasError () {
196+ t .Fatalf ("unexpected omitted-field diagnostics: %v" , diags )
197+ }
198+ if ! omitted .StartURL .IsNull () || ! omitted .TimeoutSeconds .IsNull () || ! omitted .FillRatePerMinute .IsNull () {
199+ t .Fatalf ("omitted warmup state = %#v, want null values" , omitted )
200+ }
201+
202+ boundary , diags := flattenBrowserPool (* browserPoolFromJSON (`{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"timeout_seconds":259200,"fill_rate_per_minute":0}}` ))
203+ if diags .HasError () {
204+ t .Fatalf ("unexpected boundary diagnostics: %v" , diags )
205+ }
206+ if boundary .TimeoutSeconds .ValueInt64 () != 259200 || boundary .FillRatePerMinute .IsNull () || boundary .FillRatePerMinute .IsUnknown () || boundary .FillRatePerMinute .ValueInt64 () != 0 {
207+ t .Fatalf ("boundary warmup state = %#v" , boundary )
208+ }
209+ }
210+
211+ func TestFlattenBrowserPoolRejectsInvalidWarmupConfiguration (t * testing.T ) {
212+ t .Parallel ()
213+
214+ tests := map [string ]string {
215+ "empty start URL" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"start_url":""}}` ,
216+ "null start URL" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"start_url":null}}` ,
217+ "non-string URL" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"start_url":1}}` ,
218+ "null timeout" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"timeout_seconds":null}}` ,
219+ "non-number timeout" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"timeout_seconds":"10"}}` ,
220+ "timeout too low" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"timeout_seconds":9}}` ,
221+ "timeout too high" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"timeout_seconds":259201}}` ,
222+ "null fill rate" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"fill_rate_per_minute":null}}` ,
223+ "non-number rate" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"fill_rate_per_minute":"0"}}` ,
224+ "negative fill rate" : `{"id":"pool-1","extension_ids":[],"browser_pool_config":{"size":1,"fill_rate_per_minute":-1}}` ,
225+ }
226+
227+ for name , body := range tests {
228+ t .Run (name , func (t * testing.T ) {
229+ t .Parallel ()
230+ _ , diags := flattenBrowserPool (* browserPoolFromJSON (body ))
231+ if ! diags .HasError () {
232+ t .Fatal ("expected diagnostics" )
233+ }
234+ })
235+ }
183236}
184237
185238func TestFlattenBrowserPoolLaunchConfiguration (t * testing.T ) {
@@ -422,28 +475,34 @@ func browserPoolFromJSON(body string) *kernel.BrowserPool {
422475func browserPoolConfigValue (id , name , projectID tftypes.Value ) tftypes.Value {
423476 return tftypes .NewValue (
424477 tftypes.Object {AttributeTypes : map [string ]tftypes.Type {
425- "id" : tftypes .String ,
426- "name" : tftypes .String ,
427- "project_id" : tftypes .String ,
428- "size" : tftypes .Number ,
429- "profile_id" : tftypes .String ,
430- "extension_ids" : tftypes.List {ElementType : tftypes .String },
431- "proxy_id" : tftypes .String ,
432- "headless" : tftypes .Bool ,
433- "kiosk_mode" : tftypes .Bool ,
434- "stealth" : tftypes .Bool ,
478+ "id" : tftypes .String ,
479+ "name" : tftypes .String ,
480+ "project_id" : tftypes .String ,
481+ "size" : tftypes .Number ,
482+ "profile_id" : tftypes .String ,
483+ "extension_ids" : tftypes.List {ElementType : tftypes .String },
484+ "proxy_id" : tftypes .String ,
485+ "headless" : tftypes .Bool ,
486+ "kiosk_mode" : tftypes .Bool ,
487+ "stealth" : tftypes .Bool ,
488+ "start_url" : tftypes .String ,
489+ "timeout_seconds" : tftypes .Number ,
490+ "fill_rate_per_minute" : tftypes .Number ,
435491 }},
436492 map [string ]tftypes.Value {
437- "id" : id ,
438- "name" : name ,
439- "project_id" : projectID ,
440- "size" : tftypes .NewValue (tftypes .Number , nil ),
441- "profile_id" : tftypes .NewValue (tftypes .String , nil ),
442- "extension_ids" : tftypes .NewValue (tftypes.List {ElementType : tftypes .String }, nil ),
443- "proxy_id" : tftypes .NewValue (tftypes .String , nil ),
444- "headless" : tftypes .NewValue (tftypes .Bool , nil ),
445- "kiosk_mode" : tftypes .NewValue (tftypes .Bool , nil ),
446- "stealth" : tftypes .NewValue (tftypes .Bool , nil ),
493+ "id" : id ,
494+ "name" : name ,
495+ "project_id" : projectID ,
496+ "size" : tftypes .NewValue (tftypes .Number , nil ),
497+ "profile_id" : tftypes .NewValue (tftypes .String , nil ),
498+ "extension_ids" : tftypes .NewValue (tftypes.List {ElementType : tftypes .String }, nil ),
499+ "proxy_id" : tftypes .NewValue (tftypes .String , nil ),
500+ "headless" : tftypes .NewValue (tftypes .Bool , nil ),
501+ "kiosk_mode" : tftypes .NewValue (tftypes .Bool , nil ),
502+ "stealth" : tftypes .NewValue (tftypes .Bool , nil ),
503+ "start_url" : tftypes .NewValue (tftypes .String , nil ),
504+ "timeout_seconds" : tftypes .NewValue (tftypes .Number , nil ),
505+ "fill_rate_per_minute" : tftypes .NewValue (tftypes .Number , nil ),
447506 },
448507 )
449508}
0 commit comments