@@ -472,15 +472,15 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
472472		})
473473
474474		t .Run ("ReconcileLaunchTemplate not mocked" , func (t  * testing.T ) {
475- 			g  :=  NewWithT (t )
476- 			setup (t , g )
477- 			reconciler .reconcileServiceFactory  =  nil  // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`) 
478- 			reconSvc  =  nil                            // not used 
479- 			defer  teardown (t , g )
480- 
481475			launchTemplateIDExisting  :=  "lt-existing" 
482476
483477			t .Run ("nothing exists, so launch template and ASG must be created" , func (t  * testing.T ) {
478+ 				g  :=  NewWithT (t )
479+ 				setup (t , g )
480+ 				reconciler .reconcileServiceFactory  =  nil  // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`) 
481+ 				reconSvc  =  nil                            // not used 
482+ 				defer  teardown (t , g )
483+ 
484484				ec2Svc .EXPECT ().GetLaunchTemplate (gomock .Eq ("test" )).Return (nil , "" , nil , nil )
485485				ec2Svc .EXPECT ().DiscoverLaunchTemplateAMI (gomock .Any ()).Return (ptr.To [string ]("ami-abcdef123" ), nil )
486486				ec2Svc .EXPECT ().CreateLaunchTemplate (gomock .Any (), gomock .Eq (ptr.To [string ]("ami-abcdef123" )), gomock .Eq (userDataSecretKey ), gomock .Eq ([]byte ("shell-script" ))).Return ("lt-ghijkl456" , nil )
@@ -497,6 +497,12 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
497497			})
498498
499499			t .Run ("launch template and ASG exist and need no update" , func (t  * testing.T ) {
500+ 				g  :=  NewWithT (t )
501+ 				setup (t , g )
502+ 				reconciler .reconcileServiceFactory  =  nil  // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`) 
503+ 				reconSvc  =  nil                            // not used 
504+ 				defer  teardown (t , g )
505+ 
500506				// Latest ID and version already stored, no need to retrieve it 
501507				ms .AWSMachinePool .Status .LaunchTemplateID  =  launchTemplateIDExisting 
502508				ms .AWSMachinePool .Status .LaunchTemplateVersion  =  ptr.To [string ]("1" )
@@ -538,6 +544,12 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
538544			})
539545
540546			t .Run ("launch template and ASG exist and only AMI ID changed" , func (t  * testing.T ) {
547+ 				g  :=  NewWithT (t )
548+ 				setup (t , g )
549+ 				reconciler .reconcileServiceFactory  =  nil  // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`) 
550+ 				reconSvc  =  nil                            // not used 
551+ 				defer  teardown (t , g )
552+ 
541553				// Latest ID and version already stored, no need to retrieve it 
542554				ms .AWSMachinePool .Status .LaunchTemplateID  =  launchTemplateIDExisting 
543555				ms .AWSMachinePool .Status .LaunchTemplateVersion  =  ptr.To [string ]("1" )
@@ -585,6 +597,12 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
585597			})
586598
587599			t .Run ("launch template and ASG exist and only bootstrap data secret name changed" , func (t  * testing.T ) {
600+ 				g  :=  NewWithT (t )
601+ 				setup (t , g )
602+ 				reconciler .reconcileServiceFactory  =  nil  // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`) 
603+ 				reconSvc  =  nil                            // not used 
604+ 				defer  teardown (t , g )
605+ 
588606				// Latest ID and version already stored, no need to retrieve it 
589607				ms .AWSMachinePool .Status .LaunchTemplateID  =  launchTemplateIDExisting 
590608				ms .AWSMachinePool .Status .LaunchTemplateVersion  =  ptr.To [string ]("1" )
@@ -635,6 +653,12 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
635653			})
636654
637655			t .Run ("launch template and ASG created from zero, then bootstrap config reference changes" , func (t  * testing.T ) {
656+ 				g  :=  NewWithT (t )
657+ 				setup (t , g )
658+ 				reconciler .reconcileServiceFactory  =  nil  // use real implementation, but keep EC2 calls mocked (`ec2ServiceFactory`) 
659+ 				reconSvc  =  nil                            // not used 
660+ 				defer  teardown (t , g )
661+ 
638662				ec2Svc .EXPECT ().GetLaunchTemplate (gomock .Eq ("test" )).Return (nil , "" , nil , nil )
639663				ec2Svc .EXPECT ().DiscoverLaunchTemplateAMI (gomock .Any ()).Return (ptr.To [string ]("ami-abcdef123" ), nil )
640664				ec2Svc .EXPECT ().CreateLaunchTemplate (gomock .Any (), gomock .Eq (ptr.To [string ]("ami-abcdef123" )), gomock .Eq (userDataSecretKey ), gomock .Eq ([]byte ("shell-script" ))).Return ("lt-ghijkl456" , nil )
@@ -650,7 +674,6 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
650674				g .Expect (err ).To (Succeed ())
651675
652676				g .Expect (ms .AWSMachinePool .Status .LaunchTemplateID ).ToNot (BeEmpty ())
653- 				g .Expect (ptr .Deref [string ](ms .AWSMachinePool .Status .LaunchTemplateVersion , "" )).ToNot (BeEmpty ())
654677
655678				// Data secret name changes 
656679				newBootstrapSecret  :=  & corev1.Secret {
@@ -665,6 +688,10 @@ func TestAWSMachinePoolReconciler(t *testing.T) {
665688				g .Expect (testEnv .Create (ctx , newBootstrapSecret )).To (Succeed ())
666689				ms .MachinePool .Spec .Template .Spec .Bootstrap .DataSecretName  =  ptr.To [string ](newBootstrapSecret .Name )
667690
691+ 				// Since `AWSMachinePool.status.launchTemplateVersion` isn't set yet, 
692+ 				// the controller will ask for the current version and then set the status. 
693+ 				ec2Svc .EXPECT ().GetLaunchTemplateLatestVersion (gomock .Any ()).Return ("1" , nil )
694+ 
668695				ec2Svc .EXPECT ().GetLaunchTemplate (gomock .Eq ("test" )).Return (
669696					& expinfrav1.AWSLaunchTemplate {
670697						Name : "test" ,
0 commit comments