Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfn-resources/search-deployment/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ run-contract-testing:
@echo "==> Run contract testing"
make build
sam local start-lambda &
cfn test --function-name TestEntrypoint --verbose
cfn test --verbose --enforce-timeout 3600
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] why the enforce-timeout?

43 changes: 28 additions & 15 deletions cfn-resources/search-deployment/cmd/resource/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,49 @@

package resource

import admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
import (
admin20250312010 "go.mongodb.org/atlas-sdk/v20250312010/admin"

func NewCFNSearchDeployment(prevModel *Model, apiResp *admin20231115014.ApiSearchDeploymentResponse) Model {
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
)

func NewCFNSearchDeployment(prevModel *Model, apiResp *admin20250312010.ApiSearchDeploymentResponse) Model {
respSpecs := apiResp.GetSpecs()
resultSpecs := make([]ApiSearchDeploymentSpec, len(respSpecs))
for i := range respSpecs {
instanceSize := respSpecs[i].InstanceSize
// Follow cluster pattern: directly assign NodeCount from API response
// Reference: mongodbatlas-cloudformation-resources/cfn-resources/cluster/cmd/resource/mappings.go:305,317
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, I understand how this is different than the previous implementation as that is using respSpecs as well?

also, I think you can remove this comment as the code is quite self-explanatory

// Note: API returns int, but CFN model expects *int, so convert to pointer
nodeCount := respSpecs[i].NodeCount
resultSpecs[i] = ApiSearchDeploymentSpec{
InstanceSize: &respSpecs[i].InstanceSize,
NodeCount: &respSpecs[i].NodeCount,
InstanceSize: &instanceSize,
NodeCount: util.IntPtr(nodeCount),
}
}
return Model{
Profile: prevModel.Profile,
ClusterName: prevModel.ClusterName,
ProjectId: prevModel.ProjectId,
Id: apiResp.Id,
Specs: resultSpecs,
StateName: apiResp.StateName,

finalModel := Model{
Profile: prevModel.Profile,
ClusterName: prevModel.ClusterName,
ProjectId: prevModel.ProjectId,
Id: apiResp.Id,
Specs: resultSpecs,
StateName: apiResp.StateName,
EncryptionAtRestProvider: apiResp.EncryptionAtRestProvider,
}

return finalModel
}

func NewSearchDeploymentReq(model *Model) admin20231115014.ApiSearchDeploymentRequest {
func NewSearchDeploymentReq(model *Model) admin20250312010.ApiSearchDeploymentRequest {
modelSpecs := model.Specs
requestSpecs := make([]admin20231115014.ApiSearchDeploymentSpec, len(modelSpecs))
requestSpecs := make([]admin20250312010.ApiSearchDeploymentSpec, len(modelSpecs))
for i, spec := range modelSpecs {
// Both spec fields are required in CFN model and will be defined
requestSpecs[i] = admin20231115014.ApiSearchDeploymentSpec{
requestSpecs[i] = admin20250312010.ApiSearchDeploymentSpec{
InstanceSize: *spec.InstanceSize,
NodeCount: *spec.NodeCount,
}
}
return admin20231115014.ApiSearchDeploymentRequest{Specs: requestSpecs}
return admin20250312010.ApiSearchDeploymentRequest{Specs: requestSpecs}
}
94 changes: 47 additions & 47 deletions cfn-resources/search-deployment/cmd/resource/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import (

"github.com/mongodb/mongodbatlas-cloudformation-resources/search-deployment/cmd/resource"
"github.com/stretchr/testify/assert"
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
admin20250312010 "go.mongodb.org/atlas-sdk/v20250312010/admin"
)

type sdkToCFNModelTestCase struct {
prevModel resource.Model
expectedModel resource.Model
SDKResp admin20231115014.ApiSearchDeploymentResponse
SDKResp admin20250312010.ApiSearchDeploymentResponse
name string
}

Expand All @@ -44,54 +44,54 @@ func TestSDKToCFNModel(t *testing.T) {
{
name: "Complete SDK response",
prevModel: resource.Model{
Profile: admin20231115014.PtrString(profile),
ClusterName: admin20231115014.PtrString(clusterName),
ProjectId: admin20231115014.PtrString(dummyProjectID),
Profile: admin20250312010.PtrString(profile),
ClusterName: admin20250312010.PtrString(clusterName),
ProjectId: admin20250312010.PtrString(dummyProjectID),
},
SDKResp: admin20231115014.ApiSearchDeploymentResponse{
Id: admin20231115014.PtrString(dummyDeploymentID),
GroupId: admin20231115014.PtrString(dummyProjectID),
StateName: admin20231115014.PtrString(stateName),
Specs: &[]admin20231115014.ApiSearchDeploymentSpec{
SDKResp: admin20250312010.ApiSearchDeploymentResponse{
Id: admin20250312010.PtrString(dummyDeploymentID),
GroupId: admin20250312010.PtrString(dummyProjectID),
StateName: admin20250312010.PtrString(stateName),
Specs: &[]admin20250312010.ApiSearchDeploymentSpec{
{
InstanceSize: instanceSize,
NodeCount: nodeCount,
},
},
},
expectedModel: resource.Model{
Profile: admin20231115014.PtrString(profile),
ClusterName: admin20231115014.PtrString(clusterName),
ProjectId: admin20231115014.PtrString(dummyProjectID),
Id: admin20231115014.PtrString(dummyDeploymentID),
StateName: admin20231115014.PtrString(stateName),
Profile: admin20250312010.PtrString(profile),
ClusterName: admin20250312010.PtrString(clusterName),
ProjectId: admin20250312010.PtrString(dummyProjectID),
Id: admin20250312010.PtrString(dummyDeploymentID),
StateName: admin20250312010.PtrString(stateName),
Specs: []resource.ApiSearchDeploymentSpec{
{
InstanceSize: admin20231115014.PtrString(instanceSize),
NodeCount: admin20231115014.PtrInt(nodeCount),
InstanceSize: admin20250312010.PtrString(instanceSize),
NodeCount: admin20250312010.PtrInt(nodeCount),
},
},
},
},
{
name: "Empty specs array",
prevModel: resource.Model{
Profile: admin20231115014.PtrString(profile),
ClusterName: admin20231115014.PtrString(clusterName),
ProjectId: admin20231115014.PtrString(dummyProjectID),
Profile: admin20250312010.PtrString(profile),
ClusterName: admin20250312010.PtrString(clusterName),
ProjectId: admin20250312010.PtrString(dummyProjectID),
},
SDKResp: admin20231115014.ApiSearchDeploymentResponse{
Id: admin20231115014.PtrString(dummyDeploymentID),
GroupId: admin20231115014.PtrString(dummyProjectID),
StateName: admin20231115014.PtrString(stateName),
Specs: &[]admin20231115014.ApiSearchDeploymentSpec{},
SDKResp: admin20250312010.ApiSearchDeploymentResponse{
Id: admin20250312010.PtrString(dummyDeploymentID),
GroupId: admin20250312010.PtrString(dummyProjectID),
StateName: admin20250312010.PtrString(stateName),
Specs: &[]admin20250312010.ApiSearchDeploymentSpec{},
},
expectedModel: resource.Model{
Profile: admin20231115014.PtrString(profile),
ClusterName: admin20231115014.PtrString(clusterName),
ProjectId: admin20231115014.PtrString(dummyProjectID),
Id: admin20231115014.PtrString(dummyDeploymentID),
StateName: admin20231115014.PtrString(stateName),
Profile: admin20250312010.PtrString(profile),
ClusterName: admin20250312010.PtrString(clusterName),
ProjectId: admin20250312010.PtrString(dummyProjectID),
Id: admin20250312010.PtrString(dummyDeploymentID),
StateName: admin20250312010.PtrString(stateName),
Specs: []resource.ApiSearchDeploymentSpec{},
},
},
Expand All @@ -109,25 +109,25 @@ func TestCFNModelToSDK(t *testing.T) {
testCases := []struct {
model resource.Model
name string
expectedSDKReq admin20231115014.ApiSearchDeploymentRequest
expectedSDKReq admin20250312010.ApiSearchDeploymentRequest
}{
{
name: "Complete CFN model",
model: resource.Model{
Profile: admin20231115014.PtrString(profile),
ClusterName: admin20231115014.PtrString(clusterName),
ProjectId: admin20231115014.PtrString(dummyProjectID),
Id: admin20231115014.PtrString(dummyDeploymentID),
StateName: admin20231115014.PtrString(stateName),
Profile: admin20250312010.PtrString(profile),
ClusterName: admin20250312010.PtrString(clusterName),
ProjectId: admin20250312010.PtrString(dummyProjectID),
Id: admin20250312010.PtrString(dummyDeploymentID),
StateName: admin20250312010.PtrString(stateName),
Specs: []resource.ApiSearchDeploymentSpec{
{
InstanceSize: admin20231115014.PtrString(instanceSize),
NodeCount: admin20231115014.PtrInt(nodeCount),
InstanceSize: admin20250312010.PtrString(instanceSize),
NodeCount: admin20250312010.PtrInt(nodeCount),
},
},
},
expectedSDKReq: admin20231115014.ApiSearchDeploymentRequest{
Specs: []admin20231115014.ApiSearchDeploymentSpec{
expectedSDKReq: admin20250312010.ApiSearchDeploymentRequest{
Specs: []admin20250312010.ApiSearchDeploymentSpec{
{
InstanceSize: instanceSize,
NodeCount: nodeCount,
Expand All @@ -138,15 +138,15 @@ func TestCFNModelToSDK(t *testing.T) {
{
name: "Empty specs array",
model: resource.Model{
Profile: admin20231115014.PtrString(profile),
ClusterName: admin20231115014.PtrString(clusterName),
ProjectId: admin20231115014.PtrString(dummyProjectID),
Id: admin20231115014.PtrString(dummyDeploymentID),
StateName: admin20231115014.PtrString(stateName),
Profile: admin20250312010.PtrString(profile),
ClusterName: admin20250312010.PtrString(clusterName),
ProjectId: admin20250312010.PtrString(dummyProjectID),
Id: admin20250312010.PtrString(dummyDeploymentID),
StateName: admin20250312010.PtrString(stateName),
Specs: []resource.ApiSearchDeploymentSpec{},
},
expectedSDKReq: admin20231115014.ApiSearchDeploymentRequest{
Specs: []admin20231115014.ApiSearchDeploymentSpec{},
expectedSDKReq: admin20250312010.ApiSearchDeploymentRequest{
Specs: []admin20250312010.ApiSearchDeploymentSpec{},
},
},
}
Expand Down
13 changes: 7 additions & 6 deletions cfn-resources/search-deployment/cmd/resource/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading