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