@@ -2630,3 +2630,80 @@ func TestTenantHasTargetedInstanceCreation(t *testing.T) {
26302630 })
26312631 }
26322632}
2633+
2634+ func TestEffectiveTargetedInstanceCreation (t * testing.T ) {
2635+ ctx := context .Background ()
2636+ dbSession := testCommonInitDB (t )
2637+ defer dbSession .Close ()
2638+
2639+ testCommonSetupSchema (t , dbSession )
2640+ err := dbSession .DB .ResetModel (ctx , (* cdbm .TenantSiteCapabilityAssociation )(nil ))
2641+ assert .Nil (t , err )
2642+
2643+ org := "test-eff-org"
2644+ user := testCommonBuildUser (t , dbSession , uuid .NewString (), []string {org }, []string {authz .TenantAdminRole })
2645+ ip := testCommonBuildInfrastructureProvider (t , dbSession , "Test Provider" , org , user )
2646+ site := testCommonBuildSite (t , dbSession , ip , "Test Site" , user )
2647+
2648+ // Tenant with the ceiling enabled.
2649+ tnDAO := cdbm .NewTenantDAO (dbSession )
2650+ tenantWithCeiling , err := tnDAO .CreateFromParams (ctx , nil , "ceiling-tenant" , cdb .GetStrPtr ("Ceiling Tenant" ), org , nil ,
2651+ & cdbm.TenantConfig {TargetedInstanceCreation : true }, user )
2652+ assert .Nil (t , err )
2653+ // Tenant without the ceiling.
2654+ tenantNoCeiling := testCommonBuildTenant (t , dbSession , "no-ceiling-tenant" , org + "-2" , user )
2655+
2656+ // Association row for the ceiling tenant on the site, enabled.
2657+ cdbm .TestBuildTenantSiteCapabilityAssociation (t , dbSession , tenantWithCeiling , site , true , user )
2658+ // A disabled association on a second site.
2659+ site2 := testCommonBuildSite (t , dbSession , ip , "Test Site 2" , user )
2660+ cdbm .TestBuildTenantSiteCapabilityAssociation (t , dbSession , tenantWithCeiling , site2 , false , user )
2661+ // A site with no association row at all.
2662+ site3 := testCommonBuildSite (t , dbSession , ip , "Test Site 3" , user )
2663+
2664+ tests := []struct {
2665+ name string
2666+ tenant * cdbm.Tenant
2667+ siteID uuid.UUID
2668+ expected bool
2669+ }{
2670+ {
2671+ name : "nil tenant" ,
2672+ tenant : nil ,
2673+ siteID : site .ID ,
2674+ expected : false ,
2675+ },
2676+ {
2677+ name : "ceiling disabled" ,
2678+ tenant : tenantNoCeiling ,
2679+ siteID : site .ID ,
2680+ expected : false ,
2681+ },
2682+ {
2683+ name : "ceiling enabled and association enabled" ,
2684+ tenant : tenantWithCeiling ,
2685+ siteID : site .ID ,
2686+ expected : true ,
2687+ },
2688+ {
2689+ name : "ceiling enabled but association disabled" ,
2690+ tenant : tenantWithCeiling ,
2691+ siteID : site2 .ID ,
2692+ expected : false ,
2693+ },
2694+ {
2695+ name : "ceiling enabled but no association row" ,
2696+ tenant : tenantWithCeiling ,
2697+ siteID : site3 .ID ,
2698+ expected : false ,
2699+ },
2700+ }
2701+
2702+ for _ , tc := range tests {
2703+ t .Run (tc .name , func (t * testing.T ) {
2704+ got , gerr := EffectiveTargetedInstanceCreation (ctx , nil , dbSession , tc .tenant , tc .siteID )
2705+ assert .Nil (t , gerr )
2706+ assert .Equal (t , tc .expected , got )
2707+ })
2708+ }
2709+ }
0 commit comments