@@ -22,6 +22,7 @@ import (
2222 "github.com/acorn-io/acorn/pkg/tolerations"
2323 "github.com/acorn-io/baaah/pkg/restconfig"
2424 "github.com/acorn-io/baaah/pkg/router"
25+ "github.com/acorn-io/baaah/pkg/watcher"
2526 "github.com/google/uuid"
2627 "github.com/stretchr/testify/assert"
2728 corev1 "k8s.io/api/core/v1"
@@ -1429,55 +1430,54 @@ func TestProjectUpdate(t *testing.T) {
14291430 if err != nil {
14301431 t .Fatal ("error creating client for project:" , err )
14311432 }
1433+ watchClient , err := proj1Client .GetClient ()
1434+ if err != nil {
1435+ t .Fatal ("error creating watch client for project:" , err )
1436+ }
14321437 t .Cleanup (func () {
14331438 // clean up projects
14341439 _ , err := proj1Client .ProjectDelete (ctx , projectName )
14351440 if err != nil {
14361441 t .Logf ("failed to delete project '%s': %s" , projectName , err )
14371442 }
14381443 })
1439- latestProject , err := proj1Client .ProjectGet (ctx , projectName )
1444+ var latestProject * apiv1.Project
1445+ latestProject , err = watcher.New [* apiv1.Project ](watchClient ).ByObject (ctx , proj1 , func (latestProject * apiv1.Project ) (bool , error ) {
1446+ if latestProject != nil && latestProject .Status .Namespace != "" {
1447+ return true , nil
1448+ }
1449+ return false , nil
1450+ })
14401451 if err != nil {
1441- t .Fatal ("error while getting project:" , err )
1452+ t .Fatal ("error while waiting for project to be created :" , err )
14421453 }
14431454 // update default
14441455 updatedProj , err := proj1Client .ProjectUpdate (ctx , latestProject , "new-default" , []string {"local" })
14451456 if err != nil {
14461457 t .Fatal ("error while updating project:" , err )
14471458 }
1459+
14481460 assert .Equal (t , updatedProj .Spec .DefaultRegion , "new-default" )
14491461 assert .Equal (t , updatedProj .Spec .SupportedRegions , []string {"local" , "new-default" })
14501462
1451- latestProject , err = proj1Client .ProjectGet (ctx , projectName )
1452- if err != nil {
1453- t .Fatal ("error while getting project:" , err )
1454- }
14551463 // swap default from new-default to local
1456- updatedProj , err = proj1Client .ProjectUpdate (ctx , latestProject , "local" , nil )
1464+ updatedProj , err = proj1Client .ProjectUpdate (ctx , updatedProj , "local" , nil )
14571465 if err != nil {
14581466 t .Fatal ("error while updating project:" , err )
14591467 }
14601468 assert .Equal (t , updatedProj .Spec .DefaultRegion , "local" )
14611469 assert .Equal (t , updatedProj .Spec .SupportedRegions , []string {"local" , "new-default" })
14621470
1463- latestProject , err = proj1Client .ProjectGet (ctx , projectName )
1464- if err != nil {
1465- t .Fatal ("error while getting project:" , err )
1466- }
14671471 // remove new-default region
1468- updatedProj , err = proj1Client .ProjectUpdate (ctx , latestProject , "" , []string {"local" })
1472+ updatedProj , err = proj1Client .ProjectUpdate (ctx , updatedProj , "" , []string {"local" })
14691473 if err != nil {
14701474 t .Fatal ("error while updating project:" , err )
14711475 }
14721476 assert .Equal (t , updatedProj .Spec .DefaultRegion , "local" )
14731477 assert .Equal (t , updatedProj .Spec .SupportedRegions , []string {"local" })
14741478
1475- latestProject , err = proj1Client .ProjectGet (ctx , projectName )
1476- if err != nil {
1477- t .Fatal ("error while getting project:" , err )
1478- }
14791479 // set supported regions
1480- updatedProj , err = proj1Client .ProjectUpdate (ctx , latestProject , "" , []string {"local" , "local3" , "local2" })
1480+ updatedProj , err = proj1Client .ProjectUpdate (ctx , updatedProj , "" , []string {"local" , "local3" , "local2" })
14811481 if err != nil {
14821482 t .Fatal ("error while updating project:" , err )
14831483 }
0 commit comments