@@ -522,6 +522,101 @@ func TestBuildServerlessDeployments(t *testing.T) {
522522 })
523523}
524524
525+ func TestBuildServerlessDeploymentsWithGCP (t * testing.T ) {
526+ const projectName = "testProject-2-1"
527+ const clusterName = "testCluster-2-1"
528+ const targetNamespace = "test-namespace-2-1"
529+
530+ ctl := gomock .NewController (t )
531+ clusterStore := mocks .NewMockOperatorClusterStore (ctl )
532+ dictionary := resources .AtlasNameToKubernetesName ()
533+
534+ featureValidator := mocks .NewMockFeatureValidator (ctl )
535+
536+ t .Run ("Can import Serverless deployment" , func (t * testing.T ) {
537+ speID := "TestPEId-1"
538+ speCloudProviderEndpointID := "TestCloudProviderID-1"
539+ speComment := "TestPEName-1"
540+ spePrivateEndpointIPAddress := ""
541+
542+ spe := []atlasClustersPinned.ServerlessTenantEndpoint {
543+ {
544+ Id : & speID ,
545+ CloudProviderEndpointId : & speCloudProviderEndpointID ,
546+ Comment : & speComment ,
547+ PrivateEndpointIpAddress : & spePrivateEndpointIPAddress ,
548+ ProviderName : pointer .Get ("AZURE" ),
549+ },
550+ }
551+
552+ cluster := & atlasClustersPinned.ServerlessInstanceDescription {
553+ Id : pointer .Get ("TestClusterID" ),
554+ GroupId : pointer .Get ("TestGroupID" ),
555+ MongoDBVersion : pointer .Get ("5.0" ),
556+ Name : pointer .Get (clusterName ),
557+ CreateDate : pointer .Get (time .Date (2021 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC )),
558+ ProviderSettings : atlasClustersPinned.ServerlessProviderSettings {
559+ BackingProviderName : "GCP" ,
560+ ProviderName : pointer .Get ("GCP" ),
561+ RegionName : "US_EAST_1" ,
562+ },
563+ StateName : pointer .Get ("" ),
564+ ServerlessBackupOptions : nil ,
565+ ConnectionStrings : nil ,
566+ Links : nil ,
567+ }
568+
569+ clusterStore .EXPECT ().GetServerlessInstance (projectName , clusterName ).Return (cluster , nil )
570+ clusterStore .EXPECT ().ServerlessPrivateEndpoints (projectName , clusterName ).Return (spe , nil ).Times (0 )
571+
572+ expected := & akov2.AtlasDeployment {
573+ TypeMeta : metav1.TypeMeta {
574+ Kind : "AtlasDeployment" ,
575+ APIVersion : "atlas.mongodb.com/v1" ,
576+ },
577+ ObjectMeta : metav1.ObjectMeta {
578+ Name : strings .ToLower (fmt .Sprintf ("%s-%s" , projectName , clusterName )),
579+ Namespace : targetNamespace ,
580+ Labels : map [string ]string {
581+ features .ResourceVersion : resourceVersion ,
582+ },
583+ },
584+ Spec : akov2.AtlasDeploymentSpec {
585+ Project : akov2common.ResourceRefNamespaced {
586+ Name : strings .ToLower (projectName ),
587+ Namespace : targetNamespace ,
588+ },
589+ BackupScheduleRef : akov2common.ResourceRefNamespaced {},
590+ ServerlessSpec : & akov2.ServerlessSpec {
591+ Name : cluster .GetName (),
592+ ProviderSettings : & akov2.ServerlessProviderSettingsSpec {
593+ BackingProviderName : cluster .ProviderSettings .BackingProviderName ,
594+ ProviderName : akov2provider .ProviderName (cluster .ProviderSettings .GetProviderName ()),
595+ RegionName : cluster .ProviderSettings .RegionName ,
596+ },
597+ },
598+ ProcessArgs : nil ,
599+ },
600+ Status : akov2status.AtlasDeploymentStatus {
601+ Common : akoapi.Common {
602+ Conditions : []akoapi.Condition {},
603+ },
604+ },
605+ }
606+
607+ featureValidator .EXPECT ().FeatureExist (features .ResourceAtlasDeployment , featureServerlessPrivateEndpoints ).Return (true )
608+
609+ got , err := BuildServerlessDeployments (clusterStore , featureValidator , projectName , projectName , clusterName , targetNamespace , dictionary , resourceVersion )
610+ if err != nil {
611+ t .Fatalf ("%v" , err )
612+ }
613+
614+ if ! reflect .DeepEqual (expected , got ) {
615+ t .Fatalf ("Serverless deployment mismatch.\r \n exp: %v\r \n got: %v\r \n " , expected , got )
616+ }
617+ })
618+ }
619+
525620func TestCleanTenantFields (t * testing.T ) {
526621 for _ , tt := range []struct {
527622 name string
0 commit comments