@@ -518,3 +518,85 @@ websites:
518518 assert .Contains (t , errString , "main-api: # <-- entrypoint name main-api must be in snake_case format" )
519519 assert .Contains (t , errString , "user-db: # <-- database name user-db must be in snake_case format" )
520520}
521+
522+ func TestApplication_IsValid_SubtypesOptional (t * testing.T ) {
523+ app := & Application {
524+ Name : "test-app" ,
525+ Target : "team/platform@1" ,
526+ ServiceIntents : map [string ]* ServiceIntent {
527+ "api" : {
528+ Container : Container {
529+ Docker : & Docker {Dockerfile : "Dockerfile" },
530+ },
531+ },
532+ },
533+ BucketIntents : map [string ]* BucketIntent {
534+ "storage" : {},
535+ },
536+ EntrypointIntents : map [string ]* EntrypointIntent {
537+ "main" : {
538+ Routes : map [string ]Route {
539+ "/" : {TargetName : "api" },
540+ },
541+ },
542+ },
543+ DatabaseIntents : map [string ]* DatabaseIntent {
544+ "users" : {EnvVarKey : "DATABASE_URL" },
545+ },
546+ }
547+
548+ // Without WithRequireSubtypes, validation should pass
549+ violations := app .IsValid ()
550+ assert .Len (t , violations , 0 , "Expected no violations without RequireSubtypes option, got: %v" , violations )
551+
552+ // With WithRequireSubtypes, validation should fail
553+ violations = app .IsValid (WithRequireSubtypes ())
554+ assert .NotEmpty (t , violations , "Expected violations with RequireSubtypes option" )
555+
556+ errString := FormatValidationErrors (GetSchemaValidationErrors (violations ))
557+ assert .Contains (t , errString , "api: # <-- service must have a subtype specified for build" )
558+ assert .Contains (t , errString , "storage: # <-- bucket must have a subtype specified for build" )
559+ assert .Contains (t , errString , "main: # <-- entrypoint must have a subtype specified for build" )
560+ assert .Contains (t , errString , "users: # <-- database must have a subtype specified for build" )
561+ }
562+
563+ func TestApplication_IsValid_WithSubtypes (t * testing.T ) {
564+ app := & Application {
565+ Name : "test-app" ,
566+ Target : "team/platform@1" ,
567+ ServiceIntents : map [string ]* ServiceIntent {
568+ "api" : {
569+ Resource : Resource {SubType : "fargate" },
570+ Container : Container {
571+ Docker : & Docker {Dockerfile : "Dockerfile" },
572+ },
573+ },
574+ },
575+ BucketIntents : map [string ]* BucketIntent {
576+ "storage" : {
577+ Resource : Resource {SubType : "s3" },
578+ },
579+ },
580+ EntrypointIntents : map [string ]* EntrypointIntent {
581+ "main" : {
582+ Resource : Resource {SubType : "alb" },
583+ Routes : map [string ]Route {
584+ "/" : {TargetName : "api" },
585+ },
586+ },
587+ },
588+ DatabaseIntents : map [string ]* DatabaseIntent {
589+ "users" : {
590+ Resource : Resource {SubType : "postgres" },
591+ EnvVarKey : "DATABASE_URL" ,
592+ },
593+ },
594+ }
595+
596+ // With subtypes specified, validation should pass with or without RequireSubtypes
597+ violations := app .IsValid ()
598+ assert .Len (t , violations , 0 , "Expected no violations without RequireSubtypes option, got: %v" , violations )
599+
600+ violations = app .IsValid (WithRequireSubtypes ())
601+ assert .Len (t , violations , 0 , "Expected no violations with RequireSubtypes option, got: %v" , violations )
602+ }
0 commit comments