Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-condon committed May 30, 2023
1 parent 0b0e1f8 commit ce3cfe6
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 103 deletions.
10 changes: 5 additions & 5 deletions internal/cli/atlas/clusters/availableregions/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
package availableregions

import (
"go.mongodb.org/atlas-sdk/admin"
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/internal/test"
"go.mongodb.org/atlas/mongodbatlas"
)

func TestList_Run_NoFlags(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockCloudProviderRegionsLister(ctrl)

var expected *mongodbatlas.CloudProviders
var empty []*string
var expected *admin.PaginatedApiAtlasProviderRegions
var empty []string

listOpts := &ListOpts{
store: mockStore,
Expand All @@ -52,7 +52,7 @@ func TestList_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockCloudProviderRegionsLister(ctrl)

var expected *mongodbatlas.CloudProviders
var expected *admin.PaginatedApiAtlasProviderRegions

listOpts := &ListOpts{
store: mockStore,
Expand All @@ -62,7 +62,7 @@ func TestList_Run(t *testing.T) {

mockStore.
EXPECT().
CloudProviderRegions(listOpts.ProjectID, listOpts.tier, []*string{&listOpts.provider}).
CloudProviderRegions(listOpts.ProjectID, listOpts.tier, []string{listOpts.provider}).
Return(expected, nil).
Times(1)

Expand Down
29 changes: 15 additions & 14 deletions internal/cli/atlas/clusters/region_tier_autocomplete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
package clusters

import (
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"go.mongodb.org/atlas-sdk/admin"
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongodb-atlas-cli/internal/mocks"
"github.com/stretchr/testify/require"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

func Test_autoCompleteOpts_tierSuggestions(t *testing.T) {
Expand All @@ -33,13 +34,13 @@ func Test_autoCompleteOpts_tierSuggestions(t *testing.T) {

store: mockStore,
}
expected := &atlas.CloudProviders{
Results: []*atlas.CloudProvider{
expected := &admin.PaginatedApiAtlasProviderRegions{
Results: []admin.ProviderRegions{
{
Provider: "AWS",
InstanceSizes: []*atlas.InstanceSize{
Provider: pointer.Get("AWS"),
InstanceSizes: []admin.ProviderInstanceSize{
{
Name: "M0",
Name: pointer.Get("M0"),
AvailableRegions: nil,
},
},
Expand All @@ -65,17 +66,17 @@ func Test_autoCompleteOpts_regionSuggestions(t *testing.T) {

store: mockStore,
}
expected := &atlas.CloudProviders{
Results: []*atlas.CloudProvider{
expected := &admin.PaginatedApiAtlasProviderRegions{
Results: []admin.ProviderRegions{
{
Provider: "AWS",
InstanceSizes: []*atlas.InstanceSize{
Provider: pointer.Get("AWS"),
InstanceSizes: []admin.ProviderInstanceSize{
{
Name: "M0",
AvailableRegions: []*atlas.AvailableRegion{
Name: pointer.Get("M0"),
AvailableRegions: []admin.AvailableRegion{
{
Name: "EU_EAST",
Default: false,
Name: pointer.Get("EU_EAST"),
Default: pointer.Get(false),
},
},
},
Expand Down
12 changes: 10 additions & 2 deletions internal/kubernetes/operator/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ func buildReplicationSpec(atlasRepSpec []atlasv2.ReplicationSpec) []*atlasV1.Adv
compute = &atlasV1.ComputeSpec{
Enabled: configAutoScaling.Compute.Enabled,
ScaleDownEnabled: configAutoScaling.Compute.ScaleDownEnabled,
//MinInstanceSize: configAutoScaling.Compute.MinInstanceSize,
//MaxInstanceSize: configAutoScaling.Compute.MaxInstanceSize,
MinInstanceSize: *GetInstanceSizeStringIfNotNil(configAutoScaling.Compute.MinInstanceSize),
MaxInstanceSize: *GetInstanceSizeStringIfNotNil(configAutoScaling.Compute.MaxInstanceSize),
}
}

Expand Down Expand Up @@ -463,6 +463,14 @@ func buildReplicationSpec(atlasRepSpec []atlasv2.ReplicationSpec) []*atlasV1.Adv
return result
}

func GetInstanceSizeStringIfNotNil(instanceSize *atlasv2.InstanceSize) *string{
if instanceSize == nil {
return nil
}
stringInstanceSize := string(*instanceSize)
return &stringInstanceSize
}

func BuildServerlessDeployments(deploymentStore store.AtlasOperatorClusterStore, validator features.FeatureValidator, projectID, projectName, clusterID, targetNamespace string, dictionary map[string]string, version string) (*atlasV1.AtlasDeployment, error) {
deployment, err := deploymentStore.ServerlessInstance(projectID, clusterID)
if err != nil {
Expand Down
164 changes: 82 additions & 82 deletions internal/kubernetes/operator/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,75 +56,76 @@ func TestBuildAtlasAdvancedDeployment(t *testing.T) {
firstLocation = "CA"
)

cluster := &mongodbatlas.AdvancedCluster{
cluster := &atlasv2.ClusterDescriptionV15{
BackupEnabled: pointer.Get(true),
BiConnector: &mongodbatlas.BiConnector{
BiConnector: &atlasv2.BiConnector{
Enabled: pointer.Get(true),
ReadPreference: "TestRef",
ReadPreference: pointer.Get("TestRef"),
},
ClusterType: "REPLICASET",
ClusterType: pointer.Get("REPLICASET"),
ConnectionStrings: nil,
DiskSizeGB: pointer.Get[float64](20.4),
EncryptionAtRestProvider: "TestProvider",
GroupID: "TestGroupID",
ID: "TestID",
Labels: []mongodbatlas.Label{
EncryptionAtRestProvider: pointer.Get("TestProvider"),
GroupId: pointer.Get("TestGroupID"),
Id: pointer.Get("TestID"),
Labels: []atlasv2.NDSLabel{
{
Key: "TestKey",
Value: "TestValue",
Key: pointer.Get("TestKey"),
Value: pointer.Get("TestValue"),
},
},
MongoDBMajorVersion: "5.0",
MongoDBVersion: "5.0",
Name: clusterName,
MongoDBMajorVersion: pointer.Get("5.0"),
MongoDBVersion: pointer.Get("5.0"),
Name: pointer.Get(clusterName),
Paused: pointer.Get(false),
PitEnabled: pointer.Get(true),
StateName: "RUNNING",
ReplicationSpecs: []*mongodbatlas.AdvancedReplicationSpec{
StateName: pointer.Get("RUNNING"),
ReplicationSpecs: []atlasv2.ReplicationSpec{
{
NumShards: 3,
ID: zoneID1,
ZoneName: zoneName1,
RegionConfigs: []*mongodbatlas.AdvancedRegionConfig{
NumShards: pointer.Get(3),
Id: pointer.Get(zoneID1),
ZoneName: pointer.Get(zoneName1),
RegionConfigs: []atlasv2.RegionConfig{
{
AnalyticsSpecs: &mongodbatlas.Specs{
DiskIOPS: pointer.Get[int64](10),
EbsVolumeType: "TestEBSVolume",
InstanceSize: "M20",
NodeCount: pointer.Get(3),
},
ElectableSpecs: &mongodbatlas.Specs{
DiskIOPS: pointer.Get[int64](10),
EbsVolumeType: "TestEBSVolume",
InstanceSize: "M20",
NodeCount: pointer.Get(3),
},
ReadOnlySpecs: &mongodbatlas.Specs{
DiskIOPS: pointer.Get[int64](10),
EbsVolumeType: "TestEBSVolume",
InstanceSize: "M20",
NodeCount: pointer.Get(3),
},
AutoScaling: &mongodbatlas.AdvancedAutoScaling{
DiskGB: &mongodbatlas.DiskGB{Enabled: pointer.Get(true)},
Compute: &mongodbatlas.Compute{
Enabled: pointer.Get(true),
ScaleDownEnabled: pointer.Get(true),
MinInstanceSize: "M20",
MaxInstanceSize: "M40",
AWSRegionConfig: &atlasv2.AWSRegionConfig{
AnalyticsSpecs: &atlasv2.DedicatedHardwareSpec{
DiskIOPS: pointer.Get(10),
EbsVolumeType: pointer.Get("TestEBSVolume"),
InstanceSize: pointer.Get("M20"),
NodeCount: pointer.Get(3),
},
ElectableSpecs: &atlasv2.HardwareSpec{
DiskIOPS: pointer.Get(10),
EbsVolumeType: pointer.Get("TestEBSVolume"),
InstanceSize: pointer.Get("M20"),
NodeCount: pointer.Get(3),
},
ReadOnlySpecs: &atlasv2.DedicatedHardwareSpec{
DiskIOPS: pointer.Get(10),
EbsVolumeType: pointer.Get("TestEBSVolume"),
InstanceSize: pointer.Get("M20"),
NodeCount: pointer.Get(3),
},
AutoScaling: &atlasv2.AutoScalingV15{
DiskGB: &atlasv2.DiskGBAutoScaling{Enabled: pointer.Get(true)},
Compute: &atlasv2.ComputeAutoScalingV15{
Enabled: pointer.Get(true),
ScaleDownEnabled: pointer.Get(true),
MinInstanceSize: pointer.Get(atlasv2.INSTANCESIZE_M20),
MaxInstanceSize: pointer.Get(atlasv2.INSTANCESIZE_M40),
},
},
Priority: pointer.Get(1),
ProviderName: pointer.Get("AWS"),
RegionName: pointer.Get("US_EAST_1"),
},
BackingProviderName: "AWS",
Priority: pointer.Get(1),
ProviderName: "AWS",
RegionName: "US_EAST_1",
},
},
},
},
CreateDate: "01-01-2022",
RootCertType: "TestRootCertType",
VersionReleaseSystem: "TestReleaseSystem",
CreateDate: &time.Time{},
RootCertType: pointer.Get("TestRootCertType"),
VersionReleaseSystem: pointer.Get("TestReleaseSystem"),
}
processArgs := &atlasv2.ClusterDescriptionProcessArgs{
DefaultReadConcern: pointer.Get("TestReadConcern"),
Expand Down Expand Up @@ -223,7 +224,7 @@ func TestBuildAtlasAdvancedDeployment(t *testing.T) {
CustomZoneMapping: []atlasV1.CustomZoneMapping{
{
Location: firstLocation,
Zone: cluster.ReplicationSpecs[0].ZoneName,
Zone: *cluster.ReplicationSpecs[0].ZoneName,
},
},
ManagedNamespaces: []atlasV1.ManagedNamespace{
Expand All @@ -239,62 +240,61 @@ func TestBuildAtlasAdvancedDeployment(t *testing.T) {
},
BiConnector: &atlasV1.BiConnectorSpec{
Enabled: cluster.BiConnector.Enabled,
ReadPreference: cluster.BiConnector.ReadPreference,
ReadPreference: *cluster.BiConnector.ReadPreference,
},
ClusterType: cluster.ClusterType,
EncryptionAtRestProvider: cluster.EncryptionAtRestProvider,
ClusterType: *cluster.ClusterType,
EncryptionAtRestProvider: *cluster.EncryptionAtRestProvider,
Labels: []common.LabelSpec{
{
Key: cluster.Labels[0].Key,
Value: cluster.Labels[0].Value,
Key: *cluster.Labels[0].Key,
Value: *cluster.Labels[0].Value,
},
},
Name: clusterName,
Paused: cluster.Paused,
PitEnabled: cluster.PitEnabled,
ReplicationSpecs: []*atlasV1.AdvancedReplicationSpec{
{
NumShards: cluster.ReplicationSpecs[0].NumShards,
ZoneName: cluster.ReplicationSpecs[0].ZoneName,
NumShards: *cluster.ReplicationSpecs[0].NumShards,
ZoneName: *cluster.ReplicationSpecs[0].ZoneName,
RegionConfigs: []*atlasV1.AdvancedRegionConfig{
{
AnalyticsSpecs: &atlasV1.Specs{
DiskIOPS: cluster.ReplicationSpecs[0].RegionConfigs[0].AnalyticsSpecs.DiskIOPS,
EbsVolumeType: cluster.ReplicationSpecs[0].RegionConfigs[0].AnalyticsSpecs.EbsVolumeType,
InstanceSize: cluster.ReplicationSpecs[0].RegionConfigs[0].AnalyticsSpecs.InstanceSize,
NodeCount: cluster.ReplicationSpecs[0].RegionConfigs[0].AnalyticsSpecs.NodeCount,
DiskIOPS: pointer.Get(int64(*cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.AnalyticsSpecs.DiskIOPS)),
EbsVolumeType: *cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.AnalyticsSpecs.EbsVolumeType,
InstanceSize: *cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.AnalyticsSpecs.InstanceSize,
NodeCount: cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.AnalyticsSpecs.NodeCount,
},
ElectableSpecs: &atlasV1.Specs{
DiskIOPS: cluster.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.DiskIOPS,
EbsVolumeType: cluster.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.EbsVolumeType,
InstanceSize: cluster.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize,
NodeCount: cluster.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.NodeCount,
DiskIOPS: pointer.Get(int64(*cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.ElectableSpecs.DiskIOPS)),
EbsVolumeType: *cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.ElectableSpecs.EbsVolumeType,
InstanceSize: *cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.ElectableSpecs.InstanceSize,
NodeCount: cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.ElectableSpecs.NodeCount,
},
ReadOnlySpecs: &atlasV1.Specs{
DiskIOPS: cluster.ReplicationSpecs[0].RegionConfigs[0].ReadOnlySpecs.DiskIOPS,
EbsVolumeType: cluster.ReplicationSpecs[0].RegionConfigs[0].ReadOnlySpecs.EbsVolumeType,
InstanceSize: cluster.ReplicationSpecs[0].RegionConfigs[0].ReadOnlySpecs.InstanceSize,
NodeCount: cluster.ReplicationSpecs[0].RegionConfigs[0].ReadOnlySpecs.NodeCount,
DiskIOPS: pointer.Get(int64(*cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.ReadOnlySpecs.DiskIOPS)),
EbsVolumeType: *cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.ReadOnlySpecs.EbsVolumeType,
InstanceSize: *cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.ReadOnlySpecs.InstanceSize,
NodeCount: cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.ReadOnlySpecs.NodeCount,
},
AutoScaling: &atlasV1.AdvancedAutoScalingSpec{
DiskGB: &atlasV1.DiskGB{Enabled: cluster.ReplicationSpecs[0].RegionConfigs[0].AutoScaling.DiskGB.Enabled},
DiskGB: &atlasV1.DiskGB{Enabled: cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.AutoScaling.DiskGB.Enabled},
Compute: &atlasV1.ComputeSpec{
Enabled: cluster.ReplicationSpecs[0].RegionConfigs[0].AutoScaling.Compute.Enabled,
ScaleDownEnabled: cluster.ReplicationSpecs[0].RegionConfigs[0].AutoScaling.Compute.ScaleDownEnabled,
MinInstanceSize: cluster.ReplicationSpecs[0].RegionConfigs[0].AutoScaling.Compute.MinInstanceSize,
MaxInstanceSize: cluster.ReplicationSpecs[0].RegionConfigs[0].AutoScaling.Compute.MaxInstanceSize,
Enabled: cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.AutoScaling.Compute.Enabled,
ScaleDownEnabled: cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.AutoScaling.Compute.ScaleDownEnabled,
MinInstanceSize: string(*cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.AutoScaling.Compute.MinInstanceSize),
MaxInstanceSize: string(*cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.AutoScaling.Compute.MaxInstanceSize),
},
},
BackingProviderName: cluster.ReplicationSpecs[0].RegionConfigs[0].BackingProviderName,
Priority: cluster.ReplicationSpecs[0].RegionConfigs[0].Priority,
ProviderName: cluster.ReplicationSpecs[0].RegionConfigs[0].ProviderName,
RegionName: cluster.ReplicationSpecs[0].RegionConfigs[0].RegionName,
Priority: cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.Priority,
ProviderName: *cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.ProviderName,
RegionName: *cluster.ReplicationSpecs[0].RegionConfigs[0].AWSRegionConfig.RegionName,
},
},
},
},
RootCertType: cluster.RootCertType,
VersionReleaseSystem: cluster.VersionReleaseSystem,
RootCertType: *cluster.RootCertType,
VersionReleaseSystem: *cluster.VersionReleaseSystem,
},
BackupScheduleRef: common.ResourceRefNamespaced{
Name: strings.ToLower(fmt.Sprintf("%s-%s-backupschedule", projectName, clusterName)),
Expand Down

0 comments on commit ce3cfe6

Please sign in to comment.