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
5 changes: 4 additions & 1 deletion providers/gcp/services/memorystore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ func (c *Client) convertGCPRecommendation(ctx context.Context, gcpRec *recommend
return rec
}

// memorystoreRedisServiceID is the Cloud Billing service for Cloud Memorystore for Redis.
const memorystoreRedisServiceID = "services/5AF5-2C11-D467"

// listSKUs returns the service's SKU catalog, listing it once per client so
// that pricing N recommendations costs one catalog read instead of N.
func (c *Client) listSKUs(svc BillingService) (*cloudbilling.ListSkusResponse, error) {
Expand All @@ -552,7 +555,7 @@ func (c *Client) listSKUs(svc BillingService) (*cloudbilling.ListSkusResponse, e
if c.skuCache != nil {
return c.skuCache, nil
}
skus, err := svc.ListSKUs("services/D559-82DA-3A56")
skus, err := svc.ListSKUs(memorystoreRedisServiceID)
if err != nil {
return nil, err
}
Expand Down
29 changes: 29 additions & 0 deletions providers/gcp/services/memorystore/service_id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package memorystore

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/api/cloudbilling/v1"
)

type serviceIDSpy struct{ got []string }

func (s *serviceIDSpy) ListSKUs(serviceID string) (*cloudbilling.ListSkusResponse, error) {
s.got = append(s.got, serviceID)
return &cloudbilling.ListSkusResponse{}, nil
}

// Regression for #380: the previous ID returned 404 from the live Billing API.
func TestListSKUs_UsesMemorystoreForRedisServiceID(t *testing.T) {
client, err := NewClient(context.Background(), "test-project", "us-central1")
require.NoError(t, err)
spy := &serviceIDSpy{}

_, err = client.listSKUs(spy)

require.NoError(t, err)
assert.Equal(t, []string{"services/5AF5-2C11-D467"}, spy.got)
}
Loading