1414package code_test
1515
1616import (
17+ "fmt"
1718 "testing"
1819
1920 "github.com/stretchr/testify/assert"
@@ -22,6 +23,7 @@ import (
2223 "github.com/aws-controllers-k8s/code-generator/pkg/generate/code"
2324 "github.com/aws-controllers-k8s/code-generator/pkg/model"
2425 "github.com/aws-controllers-k8s/code-generator/pkg/testutil"
26+ awssdkmodel "github.com/aws/aws-sdk-go/private/model/api"
2527)
2628
2729func TestSetResource_APIGWv2_Route_Create (t * testing.T ) {
@@ -153,6 +155,60 @@ func TestSetResource_APIGWv2_Route_ReadOne(t *testing.T) {
153155 )
154156}
155157
158+ func TestSetResource_DynamoDB_Backup_ReadOne (t * testing.T ) {
159+ assert := assert .New (t )
160+ require := require .New (t )
161+
162+ g := testutil .NewGeneratorForService (t , "dynamodb" )
163+
164+ crd := testutil .GetCRDByName (t , g , "Backup" )
165+ require .NotNil (crd )
166+
167+ expected := `
168+ if ko.Status.ACKResourceMetadata == nil {
169+ ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{}
170+ }
171+ if resp.BackupDescription.BackupDetails.BackupArn != nil {
172+ arn := ackv1alpha1.AWSResourceName(*resp.BackupDescription.BackupDetails.BackupArn)
173+ ko.Status.ACKResourceMetadata.ARN = &arn
174+ }
175+ if resp.BackupDescription.BackupDetails.BackupCreationDateTime != nil {
176+ ko.Status.BackupCreationDateTime = &metav1.Time{*resp.BackupDescription.BackupDetails.BackupCreationDateTime}
177+ } else {
178+ ko.Status.BackupCreationDateTime = nil
179+ }
180+ if resp.BackupDescription.BackupDetails.BackupExpiryDateTime != nil {
181+ ko.Status.BackupExpiryDateTime = &metav1.Time{*resp.BackupDescription.BackupDetails.BackupExpiryDateTime}
182+ } else {
183+ ko.Status.BackupExpiryDateTime = nil
184+ }
185+ if resp.BackupDescription.BackupDetails.BackupName != nil {
186+ ko.Spec.BackupName = resp.BackupDescription.BackupDetails.BackupName
187+ } else {
188+ ko.Spec.BackupName = nil
189+ }
190+ if resp.BackupDescription.BackupDetails.BackupSizeBytes != nil {
191+ ko.Status.BackupSizeBytes = resp.BackupDescription.BackupDetails.BackupSizeBytes
192+ } else {
193+ ko.Status.BackupSizeBytes = nil
194+ }
195+ if resp.BackupDescription.BackupDetails.BackupStatus != nil {
196+ ko.Status.BackupStatus = resp.BackupDescription.BackupDetails.BackupStatus
197+ } else {
198+ ko.Status.BackupStatus = nil
199+ }
200+ if resp.BackupDescription.BackupDetails.BackupType != nil {
201+ ko.Status.BackupType = resp.BackupDescription.BackupDetails.BackupType
202+ } else {
203+ ko.Status.BackupType = nil
204+ }
205+ `
206+ assert .Equal (
207+ expected ,
208+ code .SetResource (crd .Config (), crd , model .OpTypeGet , "resp" , "ko" , 1 , true ),
209+ )
210+ }
211+
156212func TestSetResource_CodeDeploy_Deployment_Create (t * testing.T ) {
157213 assert := assert .New (t )
158214 require := require .New (t )
@@ -2530,3 +2586,62 @@ func TestSetResource_RDS_DBSubnetGroup_ReadMany(t *testing.T) {
25302586 code .SetResource (crd .Config (), crd , model .OpTypeList , "resp" , "ko" , 1 , false ),
25312587 )
25322588}
2589+
2590+ func TestGetWrapperOutputShape (t * testing.T ) {
2591+ assert := assert .New (t )
2592+ require := require .New (t )
2593+
2594+ g := testutil .NewGeneratorForService (t , "dynamodb" )
2595+
2596+ crd := testutil .GetCRDByName (t , g , "Backup" )
2597+ require .NotNil (crd )
2598+
2599+ op := crd .Ops .ReadOne .OutputRef .Shape
2600+
2601+ type args struct {
2602+ outputShape * awssdkmodel.Shape
2603+ fieldPath string
2604+ }
2605+ tests := []struct {
2606+ name string
2607+ args args
2608+ wantErr bool
2609+ wantShapeName string
2610+ }{
2611+ {
2612+ name : "incorrect field path: element not found" ,
2613+ args : args {
2614+ outputShape : op ,
2615+ fieldPath : "BackupDescription.Something" ,
2616+ },
2617+ wantErr : true ,
2618+ },
2619+ {
2620+ name : "incorrect field path: element not of type structure" ,
2621+ args : args {
2622+ outputShape : op ,
2623+ fieldPath : "BackupDescription.BackupArn" ,
2624+ },
2625+ wantErr : true ,
2626+ },
2627+ {
2628+ name : "correct field path" ,
2629+ args : args {
2630+ outputShape : op ,
2631+ fieldPath : "BackupDescription.BackupDetails" ,
2632+ },
2633+ wantErr : false ,
2634+ wantShapeName : "BackupDetails" ,
2635+ },
2636+ }
2637+ for _ , tt := range tests {
2638+ t .Run (tt .name , func (t * testing.T ) {
2639+ outputShape , err := code .GetWrapperOutputShape (tt .args .outputShape , tt .args .fieldPath )
2640+ if (err != nil ) != tt .wantErr {
2641+ assert .Fail (fmt .Sprintf ("GetWrapperOutputShape() error = %v, wantErr %v" , err , tt .wantErr ))
2642+ } else if ! tt .wantErr {
2643+ assert .Equal (tt .wantShapeName , outputShape .ShapeName )
2644+ }
2645+ })
2646+ }
2647+ }
0 commit comments