File tree 2 files changed +71
-0
lines changed
2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 23
23
appSlugRegex = regexp .MustCompile (`^[a-z0-9](-?[a-z0-9])*$` )
24
24
)
25
25
26
+ const appDisplayNameMaxLength = 64 // database column limit
27
+
26
28
func appResource () * schema.Resource {
27
29
return & schema.Resource {
28
30
SchemaVersion : 1 ,
@@ -124,6 +126,17 @@ func appResource() *schema.Resource {
124
126
Description : "A display name to identify the app. Defaults to the slug." ,
125
127
ForceNew : true ,
126
128
Optional : true ,
129
+ ValidateDiagFunc : func (val interface {}, c cty.Path ) diag.Diagnostics {
130
+ valStr , ok := val .(string )
131
+ if ! ok {
132
+ return diag .Errorf ("expected string, got %T" , val )
133
+ }
134
+
135
+ if len (valStr ) > appDisplayNameMaxLength {
136
+ return diag .Errorf ("display name is too long (max %d characters)" , appDisplayNameMaxLength )
137
+ }
138
+ return nil
139
+ },
127
140
},
128
141
"subdomain" : {
129
142
Type : schema .TypeBool ,
Original file line number Diff line number Diff line change @@ -415,4 +415,62 @@ func TestApp(t *testing.T) {
415
415
}
416
416
})
417
417
418
+ t .Run ("DisplayName" , func (t * testing.T ) {
419
+ t .Parallel ()
420
+
421
+ cases := []struct {
422
+ name string
423
+ displayName string
424
+ expectValue string
425
+ expectError * regexp.Regexp
426
+ }{
427
+ {
428
+ name : "Empty" ,
429
+ displayName : "" ,
430
+ },
431
+ {
432
+ name : "Regular" ,
433
+ displayName : "Regular Application" ,
434
+ },
435
+ {
436
+ name : "DisplayNameTooLong" ,
437
+ displayName : "01234567890123456789012345678901234567890123456789012345678901234" ,
438
+ expectError : regexp .MustCompile ("display name is too long" ),
439
+ },
440
+ }
441
+
442
+ for _ , c := range cases {
443
+ c := c
444
+
445
+ t .Run (c .name , func (t * testing.T ) {
446
+ t .Parallel ()
447
+
448
+ config := fmt .Sprintf (`
449
+ provider "coder" {
450
+ }
451
+ resource "coder_agent" "dev" {
452
+ os = "linux"
453
+ arch = "amd64"
454
+ }
455
+ resource "coder_app" "code-server" {
456
+ agent_id = coder_agent.dev.id
457
+ slug = "code-server"
458
+ display_name = "%s"
459
+ url = "http://localhost:13337"
460
+ open_in = "slim-window"
461
+ }
462
+ ` , c .displayName )
463
+
464
+ resource .Test (t , resource.TestCase {
465
+ ProviderFactories : coderFactory (),
466
+ IsUnitTest : true ,
467
+ Steps : []resource.TestStep {{
468
+ Config : config ,
469
+ ExpectError : c .expectError ,
470
+ }},
471
+ })
472
+ })
473
+ }
474
+ })
475
+
418
476
}
You can’t perform that action at this time.
0 commit comments