Skip to content

Commit 9b3f292

Browse files
authored
fix: Correctly handle success in DryRun invocation (#1966)
#### Summary
1 parent 763d55f commit 9b3f292

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

premium/usage.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
awsConfig "github.com/aws/aws-sdk-go-v2/config"
1616
"github.com/aws/aws-sdk-go-v2/service/marketplacemetering"
1717
"github.com/aws/aws-sdk-go-v2/service/marketplacemetering/types"
18-
"github.com/aws/smithy-go"
1918
cqapi "github.com/cloudquery/cloudquery-api-go"
2019
"github.com/cloudquery/cloudquery-api-go/auth"
2120
"github.com/cloudquery/cloudquery-api-go/config"
@@ -316,11 +315,10 @@ func (u *BatchUpdater) setupAWSMarketplace() error {
316315
UsageQuantity: aws.Int32(int32(0)),
317316
DryRun: aws.Bool(true),
318317
})
319-
var apiErr smithy.APIError
320-
if errors.As(err, &apiErr) && apiErr.ErrorCode() == "DryRunOperation" {
321-
return nil
318+
if err != nil {
319+
return fmt.Errorf("failed dry run invocation with error: %w", err)
322320
}
323-
return fmt.Errorf("failed dry run invocation with error: %w", err)
321+
return nil
324322
}
325323

326324
func isAWSMarketplace() bool {

premium/usage_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/aws/aws-sdk-go-v2/aws"
1616
"github.com/aws/aws-sdk-go-v2/service/marketplacemetering"
1717
"github.com/aws/aws-sdk-go-v2/service/marketplacemetering/types"
18-
"github.com/aws/smithy-go"
1918
cqapi "github.com/cloudquery/cloudquery-api-go"
2019
"github.com/cloudquery/cloudquery-api-go/auth"
2120
"github.com/cloudquery/cloudquery-api-go/config"
@@ -370,10 +369,12 @@ func usageMarketplaceDryRunHelper(t *testing.T, m *mocks.MockAWSMarketplaceClien
370369
UsageQuantity: aws.Int32(int32(0)),
371370
DryRun: aws.Bool(true)},
372371
}
373-
errTest := smithy.GenericAPIError{Code: "DryRunOperation", Message: "No errors detected in dry run"}
374-
out := marketplacemetering.MeterUsageOutput{}
375372

376-
return m.EXPECT().MeterUsage(gomock.Any(), inTest).Return(&out, &errTest)
373+
out := marketplacemetering.MeterUsageOutput{
374+
MeteringRecordId: aws.String("DryRunOperation"),
375+
}
376+
377+
return m.EXPECT().MeterUsage(gomock.Any(), inTest).Return(&out, nil)
377378
}
378379

379380
func TestUsageService_AWSMarketplaceDone(t *testing.T) {

0 commit comments

Comments
 (0)