Skip to content

Commit 62f4660

Browse files
authored
Merge pull request #835 from alexeldeib/ace/bugz
🐛 sku api should use resourceType, not kind
2 parents 9dec43b + 36e7e1f commit 62f4660

File tree

3 files changed

+47
-63
lines changed

3 files changed

+47
-63
lines changed

cloud/services/resourceskus/cache.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (c *Cache) refresh(ctx context.Context, location string) error {
8484
// enhancing this function to handle restrictions (e.g. SKU not
8585
// supported in region), which is why it returns an error and not a
8686
// boolean.
87-
func (c *Cache) Get(ctx context.Context, name string, kind Kind) (SKU, error) {
87+
func (c *Cache) Get(ctx context.Context, name string, kind ResourceType) (SKU, error) {
8888
if c.data == nil {
8989
if err := c.refresh(ctx, c.location); err != nil {
9090
return SKU{}, err
@@ -99,22 +99,6 @@ func (c *Cache) Get(ctx context.Context, name string, kind Kind) (SKU, error) {
9999
return SKU{}, fmt.Errorf("resource sku with name '%s' and category '%s' not found", name, string(kind))
100100
}
101101

102-
// List returns a list of all known SKUs, useful for further filtering.
103-
func (c *Cache) List(ctx context.Context, name string, kind Kind) ([]SKU, error) {
104-
if c.data == nil {
105-
if err := c.refresh(ctx, c.location); err != nil {
106-
return nil, err
107-
}
108-
}
109-
110-
// return a converted copy so clients do not mutate underlying data.
111-
var skus = make([]SKU, len(c.data))
112-
for i := range c.data {
113-
skus[i] = SKU(c.data[i])
114-
}
115-
return skus, nil
116-
}
117-
118102
// Map invokes a function over all cached values.
119103
func (c *Cache) Map(ctx context.Context, mapFn func(sku SKU)) error {
120104
if c.data == nil {
@@ -138,7 +122,7 @@ func (c *Cache) GetZones(ctx context.Context, location string) ([]string, error)
138122
var allZones = make(map[string]bool)
139123
mapFn := func(sku SKU) {
140124
// Look for VMs only
141-
if sku.Kind != nil && strings.EqualFold(*sku.Kind, string(VirtualMachines)) {
125+
if sku.ResourceType != nil && strings.EqualFold(*sku.ResourceType, string(VirtualMachines)) {
142126
// find matching location
143127
for _, locationInfo := range *sku.LocationInfo {
144128
if strings.EqualFold(*locationInfo.Location, location) {
@@ -196,7 +180,7 @@ func (c *Cache) GetZones(ctx context.Context, location string) ([]string, error)
196180
func (c *Cache) GetZonesWithVMSize(ctx context.Context, size, location string) ([]string, error) {
197181
var allZones = make(map[string]bool)
198182
mapFn := func(sku SKU) {
199-
if sku.Name != nil && strings.EqualFold(*sku.Name, size) && sku.Kind != nil && strings.EqualFold(*sku.Kind, string(VirtualMachines)) {
183+
if sku.Name != nil && strings.EqualFold(*sku.Name, size) && sku.ResourceType != nil && strings.EqualFold(*sku.ResourceType, string(VirtualMachines)) {
200184
// find matching location
201185
for _, locationInfo := range *sku.LocationInfo {
202186
if strings.EqualFold(*locationInfo.Location, location) {

cloud/services/resourceskus/cache_test.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ import (
2828

2929
func TestCacheGet(t *testing.T) {
3030
cases := map[string]struct {
31-
sku string
32-
kind Kind
33-
have []compute.ResourceSku
34-
err string
31+
sku string
32+
resourceType ResourceType
33+
have []compute.ResourceSku
34+
err string
3535
}{
3636
"should find": {
37-
sku: "foo",
38-
kind: "bar",
37+
sku: "foo",
38+
resourceType: "bar",
3939
have: []compute.ResourceSku{
4040
{
41-
Name: to.StringPtr("other"),
42-
Kind: to.StringPtr("baz"),
41+
Name: to.StringPtr("other"),
42+
ResourceType: to.StringPtr("baz"),
4343
},
4444
{
45-
Name: to.StringPtr("foo"),
46-
Kind: to.StringPtr("bar"),
45+
Name: to.StringPtr("foo"),
46+
ResourceType: to.StringPtr("bar"),
4747
},
4848
},
4949
},
5050
"should not find": {
51-
sku: "foo",
52-
kind: "bar",
51+
sku: "foo",
52+
resourceType: "bar",
5353
have: []compute.ResourceSku{
5454
{
5555
Name: to.StringPtr("other"),
@@ -68,7 +68,7 @@ func TestCacheGet(t *testing.T) {
6868
data: tc.have,
6969
}
7070

71-
val, err := cache.Get(context.Background(), tc.sku, tc.kind)
71+
val, err := cache.Get(context.Background(), tc.sku, tc.resourceType)
7272
if tc.err != "" {
7373
if err == nil {
7474
t.Fatalf("expected cache.get to fail with error %s, but actual error was nil", tc.err)
@@ -86,12 +86,12 @@ func TestCacheGet(t *testing.T) {
8686
if *val.Name != tc.sku {
8787
t.Fatalf("expected name to be %s, but was %s", tc.sku, *val.Name)
8888
}
89-
if val.Kind == nil {
89+
if val.ResourceType == nil {
9090
t.Fatalf("expected name to be %s, but was nil", tc.sku)
9191
return
9292
}
93-
if *val.Kind != string(tc.kind) {
94-
t.Fatalf("expected kind to be %s, but was %s", tc.kind, *val.Kind)
93+
if *val.ResourceType != string(tc.resourceType) {
94+
t.Fatalf("expected kind to be %s, but was %s", tc.resourceType, *val.ResourceType)
9595
}
9696
}
9797

@@ -107,8 +107,8 @@ func TestCacheGetZones(t *testing.T) {
107107
"should find 1 result": {
108108
have: []compute.ResourceSku{
109109
{
110-
Name: to.StringPtr("foo"),
111-
Kind: to.StringPtr(string(VirtualMachines)),
110+
Name: to.StringPtr("foo"),
111+
ResourceType: to.StringPtr(string(VirtualMachines)),
112112
Locations: &[]string{
113113
"baz",
114114
},
@@ -125,8 +125,8 @@ func TestCacheGetZones(t *testing.T) {
125125
"should find 2 results": {
126126
have: []compute.ResourceSku{
127127
{
128-
Name: to.StringPtr("foo"),
129-
Kind: to.StringPtr(string(VirtualMachines)),
128+
Name: to.StringPtr("foo"),
129+
ResourceType: to.StringPtr(string(VirtualMachines)),
130130
Locations: &[]string{
131131
"baz",
132132
},
@@ -138,8 +138,8 @@ func TestCacheGetZones(t *testing.T) {
138138
},
139139
},
140140
{
141-
Name: to.StringPtr("foo"),
142-
Kind: to.StringPtr(string(VirtualMachines)),
141+
Name: to.StringPtr("foo"),
142+
ResourceType: to.StringPtr(string(VirtualMachines)),
143143
Locations: &[]string{
144144
"baz",
145145
},
@@ -156,8 +156,8 @@ func TestCacheGetZones(t *testing.T) {
156156
"should not find due to location mismatch": {
157157
have: []compute.ResourceSku{
158158
{
159-
Name: to.StringPtr("foo"),
160-
Kind: to.StringPtr(string(VirtualMachines)),
159+
Name: to.StringPtr("foo"),
160+
ResourceType: to.StringPtr(string(VirtualMachines)),
161161
Locations: &[]string{
162162
"foobar",
163163
},
@@ -174,8 +174,8 @@ func TestCacheGetZones(t *testing.T) {
174174
"should not find due to location restriction": {
175175
have: []compute.ResourceSku{
176176
{
177-
Name: to.StringPtr("foo"),
178-
Kind: to.StringPtr(string(VirtualMachines)),
177+
Name: to.StringPtr("foo"),
178+
ResourceType: to.StringPtr(string(VirtualMachines)),
179179
Locations: &[]string{
180180
"baz",
181181
},
@@ -198,8 +198,8 @@ func TestCacheGetZones(t *testing.T) {
198198
"should not find due to zone restriction": {
199199
have: []compute.ResourceSku{
200200
{
201-
Name: to.StringPtr("foo"),
202-
Kind: to.StringPtr(string(VirtualMachines)),
201+
Name: to.StringPtr("foo"),
202+
ResourceType: to.StringPtr(string(VirtualMachines)),
203203
Locations: &[]string{
204204
"baz",
205205
},
@@ -251,8 +251,8 @@ func TestCacheGetZonesWithVMSize(t *testing.T) {
251251
"should find 1 result": {
252252
have: []compute.ResourceSku{
253253
{
254-
Name: to.StringPtr("foo"),
255-
Kind: to.StringPtr(string(VirtualMachines)),
254+
Name: to.StringPtr("foo"),
255+
ResourceType: to.StringPtr(string(VirtualMachines)),
256256
Locations: &[]string{
257257
"baz",
258258
},
@@ -269,8 +269,8 @@ func TestCacheGetZonesWithVMSize(t *testing.T) {
269269
"should find 2 results": {
270270
have: []compute.ResourceSku{
271271
{
272-
Name: to.StringPtr("foo"),
273-
Kind: to.StringPtr(string(VirtualMachines)),
272+
Name: to.StringPtr("foo"),
273+
ResourceType: to.StringPtr(string(VirtualMachines)),
274274
Locations: &[]string{
275275
"baz",
276276
},
@@ -287,8 +287,8 @@ func TestCacheGetZonesWithVMSize(t *testing.T) {
287287
"should not find due to size mismatch": {
288288
have: []compute.ResourceSku{
289289
{
290-
Name: to.StringPtr("foobar"),
291-
Kind: to.StringPtr(string(VirtualMachines)),
290+
Name: to.StringPtr("foobar"),
291+
ResourceType: to.StringPtr(string(VirtualMachines)),
292292
Locations: &[]string{
293293
"baz",
294294
},
@@ -305,8 +305,8 @@ func TestCacheGetZonesWithVMSize(t *testing.T) {
305305
"should not find due to location mismatch": {
306306
have: []compute.ResourceSku{
307307
{
308-
Name: to.StringPtr("foo"),
309-
Kind: to.StringPtr(string(VirtualMachines)),
308+
Name: to.StringPtr("foo"),
309+
ResourceType: to.StringPtr(string(VirtualMachines)),
310310
Locations: &[]string{
311311
"foobar",
312312
},
@@ -323,8 +323,8 @@ func TestCacheGetZonesWithVMSize(t *testing.T) {
323323
"should not find due to location restriction": {
324324
have: []compute.ResourceSku{
325325
{
326-
Name: to.StringPtr("foo"),
327-
Kind: to.StringPtr(string(VirtualMachines)),
326+
Name: to.StringPtr("foo"),
327+
ResourceType: to.StringPtr(string(VirtualMachines)),
328328
Locations: &[]string{
329329
"baz",
330330
},
@@ -347,8 +347,8 @@ func TestCacheGetZonesWithVMSize(t *testing.T) {
347347
"should not find due to zone restriction": {
348348
have: []compute.ResourceSku{
349349
{
350-
Name: to.StringPtr("foo"),
351-
Kind: to.StringPtr(string(VirtualMachines)),
350+
Name: to.StringPtr("foo"),
351+
ResourceType: to.StringPtr(string(VirtualMachines)),
352352
Locations: &[]string{
353353
"baz",
354354
},

cloud/services/resourceskus/sku.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ import (
2727
// SKU is a thin layer over the Azure resource SKU API to better introspect capabilities
2828
type SKU compute.ResourceSku
2929

30-
// Kind models available resource types as a set of known string constants.
31-
type Kind string
30+
// ResourceType models available resource types as a set of known string constants.
31+
type ResourceType string
3232

3333
const (
3434
// VirtualMachines is a convenience constant to filter resource SKUs to only include VMs.
35-
VirtualMachines Kind = "virtualMachines"
35+
VirtualMachines ResourceType = "virtualMachines"
3636
// Disks is a convenience constant to filter resource SKUs to only include disks.
37-
Disks Kind = "disks"
37+
Disks ResourceType = "disks"
3838
)
3939

4040
// Supported models an enum of possible boolean values for resource support in the Azure API.

0 commit comments

Comments
 (0)