| 
 | 1 | +package controllers  | 
 | 2 | + | 
 | 3 | +import (  | 
 | 4 | +	"context"  | 
 | 5 | +	"testing"  | 
 | 6 | + | 
 | 7 | +	asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"  | 
 | 8 | +	"github.com/Azure/azure-service-operator/v2/pkg/genruntime"  | 
 | 9 | +	. "github.com/onsi/gomega"  | 
 | 10 | +	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"  | 
 | 11 | +	"k8s.io/apimachinery/pkg/types"  | 
 | 12 | +	"k8s.io/utils/ptr"  | 
 | 13 | +	infrav1alpha "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha1"  | 
 | 14 | +	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"  | 
 | 15 | +	ctrl "sigs.k8s.io/controller-runtime"  | 
 | 16 | +	"sigs.k8s.io/controller-runtime/pkg/client/fake"  | 
 | 17 | +)  | 
 | 18 | + | 
 | 19 | +func TestAgentPoolAdoptController(t *testing.T) {  | 
 | 20 | +	g := NewWithT(t)  | 
 | 21 | +	req := ctrl.Request{NamespacedName: types.NamespacedName{Name: "fake-agent-pool", Namespace: "fake-ns"}}  | 
 | 22 | +	ctx := context.Background()  | 
 | 23 | +	scheme, err := newScheme()  | 
 | 24 | +	g.Expect(err).To(BeNil())  | 
 | 25 | + | 
 | 26 | +	agentPool := &asocontainerservicev1.ManagedClustersAgentPool{  | 
 | 27 | +		ObjectMeta: metav1.ObjectMeta{  | 
 | 28 | +			Name:      "fake-agent-pool",  | 
 | 29 | +			Namespace: "fake-ns",  | 
 | 30 | +			Annotations: map[string]string{  | 
 | 31 | +				adoptAnnotation: adoptAnnotationValue,  | 
 | 32 | +			},  | 
 | 33 | +			OwnerReferences: []metav1.OwnerReference{  | 
 | 34 | +				{  | 
 | 35 | +					Kind:       infrav1alpha.AzureASOManagedMachinePoolKind,  | 
 | 36 | +					APIVersion: infrav1alpha.GroupVersion.Identifier(),  | 
 | 37 | +				},  | 
 | 38 | +			},  | 
 | 39 | +		},  | 
 | 40 | +		Spec: asocontainerservicev1.ManagedClustersAgentPool_Spec{  | 
 | 41 | +			Count: ptr.To(1),  | 
 | 42 | +			Owner: &genruntime.KnownResourceReference{  | 
 | 43 | +				Name: "fake-managed-cluster",  | 
 | 44 | +			},  | 
 | 45 | +		},  | 
 | 46 | +	}  | 
 | 47 | +	mc := &asocontainerservicev1.ManagedCluster{  | 
 | 48 | +		ObjectMeta: metav1.ObjectMeta{  | 
 | 49 | +			Name:      "fake-managed-cluster",  | 
 | 50 | +			Namespace: "fake-ns",  | 
 | 51 | +			OwnerReferences: []metav1.OwnerReference{  | 
 | 52 | +				{  | 
 | 53 | +					Kind:       infrav1alpha.AzureASOManagedControlPlaneKind,  | 
 | 54 | +					APIVersion: infrav1alpha.GroupVersion.Identifier(),  | 
 | 55 | +					Name:       "fake-managed-cluster",  | 
 | 56 | +				},  | 
 | 57 | +			},  | 
 | 58 | +		},  | 
 | 59 | +	}  | 
 | 60 | +	asoManagedControlPlane := &infrav1alpha.AzureASOManagedControlPlane{  | 
 | 61 | +		ObjectMeta: metav1.ObjectMeta{  | 
 | 62 | +			Name:      "fake-managed-cluster",  | 
 | 63 | +			Namespace: "fake-ns",  | 
 | 64 | +			Labels: map[string]string{  | 
 | 65 | +				clusterv1.ClusterNameLabel: "cluster-name",  | 
 | 66 | +			},  | 
 | 67 | +		},  | 
 | 68 | +	}  | 
 | 69 | + | 
 | 70 | +	asocontainerservicev1.AddToScheme(scheme)  | 
 | 71 | +	infrav1alpha.AddToScheme(scheme)  | 
 | 72 | +	client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(agentPool, mc, asoManagedControlPlane).WithStatusSubresource(mc, agentPool, asoManagedControlPlane).Build()  | 
 | 73 | +	aprec := &AgentPoolAdoptReconciler{  | 
 | 74 | +		Client: client,  | 
 | 75 | +	}  | 
 | 76 | +	_, err = aprec.Reconcile(ctx, req)  | 
 | 77 | +	g.Expect(err).To(BeNil())  | 
 | 78 | +}  | 
0 commit comments