Skip to content
Merged
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: 2 additions & 0 deletions providers/aws/recommendations/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type CostExplorerAPI interface {
GetSavingsPlansPurchaseRecommendation(ctx context.Context, params *costexplorer.GetSavingsPlansPurchaseRecommendationInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansPurchaseRecommendationOutput, error)
GetReservationUtilization(ctx context.Context, params *costexplorer.GetReservationUtilizationInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetReservationUtilizationOutput, error)
GetReservationCoverage(ctx context.Context, params *costexplorer.GetReservationCoverageInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetReservationCoverageOutput, error)
GetSavingsPlansCoverage(ctx context.Context, params *costexplorer.GetSavingsPlansCoverageInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansCoverageOutput, error)
GetSavingsPlansUtilization(ctx context.Context, params *costexplorer.GetSavingsPlansUtilizationInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansUtilizationOutput, error)
}

// Client wraps the AWS Cost Explorer client for RI recommendations
Expand Down
32 changes: 32 additions & 0 deletions providers/aws/recommendations/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ func (m *mockCostExplorerAPI) GetReservationCoverage(ctx context.Context, params
return &costexplorer.GetReservationCoverageOutput{}, nil
}

func (m *mockCostExplorerAPI) GetSavingsPlansCoverage(ctx context.Context, params *costexplorer.GetSavingsPlansCoverageInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansCoverageOutput, error) {
return &costexplorer.GetSavingsPlansCoverageOutput{}, nil
}

func (m *mockCostExplorerAPI) GetSavingsPlansUtilization(ctx context.Context, params *costexplorer.GetSavingsPlansUtilizationInput, optFns ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansUtilizationOutput, error) {
return &costexplorer.GetSavingsPlansUtilizationOutput{}, nil
}

func TestNewClient(t *testing.T) {
cfg := aws.Config{
Region: "us-west-2",
Expand Down Expand Up @@ -681,6 +689,18 @@ func (m *multiPageRIMock) GetReservationCoverage(
return &costexplorer.GetReservationCoverageOutput{}, nil
}

func (m *multiPageRIMock) GetSavingsPlansCoverage(
_ context.Context, _ *costexplorer.GetSavingsPlansCoverageInput, _ ...func(*costexplorer.Options),
) (*costexplorer.GetSavingsPlansCoverageOutput, error) {
return &costexplorer.GetSavingsPlansCoverageOutput{}, nil
}

func (m *multiPageRIMock) GetSavingsPlansUtilization(
_ context.Context, _ *costexplorer.GetSavingsPlansUtilizationInput, _ ...func(*costexplorer.Options),
) (*costexplorer.GetSavingsPlansUtilizationOutput, error) {
return &costexplorer.GetSavingsPlansUtilizationOutput{}, nil
}

// riDetail returns a minimal ReservationPurchaseRecommendation with n EC2 details.
func riDetail(n int) types.ReservationPurchaseRecommendation {
details := make([]types.ReservationPurchaseRecommendationDetail, n)
Expand Down Expand Up @@ -801,6 +821,18 @@ func (m *alwaysNextPageRIMock) GetReservationCoverage(
return &costexplorer.GetReservationCoverageOutput{}, nil
}

func (m *alwaysNextPageRIMock) GetSavingsPlansCoverage(
_ context.Context, _ *costexplorer.GetSavingsPlansCoverageInput, _ ...func(*costexplorer.Options),
) (*costexplorer.GetSavingsPlansCoverageOutput, error) {
return &costexplorer.GetSavingsPlansCoverageOutput{}, nil
}

func (m *alwaysNextPageRIMock) GetSavingsPlansUtilization(
_ context.Context, _ *costexplorer.GetSavingsPlansUtilizationInput, _ ...func(*costexplorer.Options),
) (*costexplorer.GetSavingsPlansUtilizationOutput, error) {
return &costexplorer.GetSavingsPlansUtilizationOutput{}, nil
}

// TestGetRecommendations_RI_PaginationCapError asserts that exceeding
// maxRecommendationPages returns a diagnostic error (issue #692).
func TestGetRecommendations_RI_PaginationCapError(t *testing.T) {
Expand Down
32 changes: 32 additions & 0 deletions providers/aws/recommendations/parser_sp_additional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ func (m *mockCostExplorerForSP) GetReservationCoverage(ctx context.Context, para
return &costexplorer.GetReservationCoverageOutput{}, nil
}

func (m *mockCostExplorerForSP) GetSavingsPlansCoverage(_ context.Context, _ *costexplorer.GetSavingsPlansCoverageInput, _ ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansCoverageOutput, error) {
return &costexplorer.GetSavingsPlansCoverageOutput{}, nil
}

func (m *mockCostExplorerForSP) GetSavingsPlansUtilization(_ context.Context, _ *costexplorer.GetSavingsPlansUtilizationInput, _ ...func(*costexplorer.Options)) (*costexplorer.GetSavingsPlansUtilizationOutput, error) {
return &costexplorer.GetSavingsPlansUtilizationOutput{}, nil
}

func TestGetSavingsPlansRecommendations_WithFilters(t *testing.T) {
mockAPI := &mockCostExplorerForSP{
responses: map[types.SupportedSavingsPlansType]*costexplorer.GetSavingsPlansPurchaseRecommendationOutput{
Expand Down Expand Up @@ -434,6 +442,18 @@ func (m *multiPageSPMock) GetReservationCoverage(
return &costexplorer.GetReservationCoverageOutput{}, nil
}

func (m *multiPageSPMock) GetSavingsPlansCoverage(
_ context.Context, _ *costexplorer.GetSavingsPlansCoverageInput, _ ...func(*costexplorer.Options),
) (*costexplorer.GetSavingsPlansCoverageOutput, error) {
return &costexplorer.GetSavingsPlansCoverageOutput{}, nil
}

func (m *multiPageSPMock) GetSavingsPlansUtilization(
_ context.Context, _ *costexplorer.GetSavingsPlansUtilizationInput, _ ...func(*costexplorer.Options),
) (*costexplorer.GetSavingsPlansUtilizationOutput, error) {
return &costexplorer.GetSavingsPlansUtilizationOutput{}, nil
}

// alwaysNextPageSPMock returns pages each carrying a non-nil non-empty NextPageToken.
type alwaysNextPageSPMock struct {
calls int
Expand Down Expand Up @@ -466,6 +486,18 @@ func (m *alwaysNextPageSPMock) GetReservationCoverage(
return &costexplorer.GetReservationCoverageOutput{}, nil
}

func (m *alwaysNextPageSPMock) GetSavingsPlansCoverage(
_ context.Context, _ *costexplorer.GetSavingsPlansCoverageInput, _ ...func(*costexplorer.Options),
) (*costexplorer.GetSavingsPlansCoverageOutput, error) {
return &costexplorer.GetSavingsPlansCoverageOutput{}, nil
}

func (m *alwaysNextPageSPMock) GetSavingsPlansUtilization(
_ context.Context, _ *costexplorer.GetSavingsPlansUtilizationInput, _ ...func(*costexplorer.Options),
) (*costexplorer.GetSavingsPlansUtilizationOutput, error) {
return &costexplorer.GetSavingsPlansUtilizationOutput{}, nil
}

// TestGetSavingsPlansRecommendations_Paginates asserts multi-page accumulation (issue #692).
func TestGetSavingsPlansRecommendations_Paginates(t *testing.T) {
mock := &multiPageSPMock{
Expand Down
Loading
Loading