Skip to content

Commit f2a784d

Browse files
author
Ace Eldeib
authored
fix: interface break for 2021-12-01 api (#15)
1 parent 7b622b6 commit f2a784d

File tree

13 files changed

+63
-38
lines changed

13 files changed

+63
-38
lines changed

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,18 @@ linters:
7777
- gocyclo
7878
- gofmt
7979
- goimports
80-
- golint
8180
- gomnd
8281
- goprintffuncname
8382
- gosec
8483
- gosimple
8584
- govet
8685
- ineffassign
87-
- interfacer
8886
- lll
8987
- misspell
9088
- nakedret
9189
- noctx
9290
- nolintlint
9391
- rowserrcheck
94-
- scopelint
9592
- staticcheck
9693
- structcheck
9794
- stylecheck

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"fmt"
1717

1818
"github.com/Azure/go-autorest/autorest/azure/auth"
19-
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute"
19+
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute" //nolint:staticcheck
2020

2121
"github.com/Azure/skewer"
2222
)

cache.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88

99
// Config contains configuration options for a cache.
1010
type Config struct {
11-
location string
12-
filter string
13-
client client
11+
location string
12+
includeExtendedLocations string
13+
filter string
14+
client client
1415
}
1516

1617
// Cache stores a list of known skus, possibly fetched with a provided client
@@ -31,6 +32,14 @@ func WithLocation(location string) Option {
3132
}
3233
}
3334

35+
// WithExtendedLocations is a functional option to include extended locations
36+
func WithExtendedLocations() Option {
37+
return func(c *Config) (*Config, error) {
38+
c.includeExtendedLocations = "true"
39+
return c, nil
40+
}
41+
}
42+
3443
// ErrClientNil will be returned when a user attempts to create a cache
3544
// without a client and use it.
3645
type ErrClientNil struct {
@@ -139,7 +148,7 @@ func NewStaticCache(data []SKU, opts ...Option) (*Cache, error) {
139148
}
140149

141150
func (c *Cache) refresh(ctx context.Context) error {
142-
data, err := c.config.client.List(ctx, c.config.filter)
151+
data, err := c.config.client.List(ctx, c.config.filter, c.config.includeExtendedLocations)
143152
if err != nil {
144153
return err
145154
}

cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
"testing"
77

8-
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute"
8+
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute" //nolint:staticcheck
99
"github.com/Azure/go-autorest/autorest/to"
1010
"github.com/google/go-cmp/cmp"
1111
"github.com/google/go-cmp/cmp/cmpopts"

clients.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package skewer
33
import (
44
"context"
55

6-
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute"
6+
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute" //nolint:staticcheck
77
"github.com/pkg/errors"
88
)
99

@@ -18,8 +18,8 @@ func newWrappedResourceClient(client ResourceClient) *wrappedResourceClient {
1818
}
1919

2020
// List greedily traverses all returned sku pages
21-
func (w *wrappedResourceClient) List(ctx context.Context, filter string) ([]compute.ResourceSku, error) {
22-
return iterate(ctx, filter, w.client.ListComplete)
21+
func (w *wrappedResourceClient) List(ctx context.Context, filter, includeExtendedLocations string) ([]compute.ResourceSku, error) {
22+
return iterate(ctx, filter, includeExtendedLocations, w.client.ListComplete)
2323
}
2424

2525
// wrappedResourceProviderClient defines a wrapper for the typical Azure client
@@ -33,19 +33,20 @@ func newWrappedResourceProviderClient(client ResourceProviderClient) *wrappedRes
3333
return &wrappedResourceProviderClient{client}
3434
}
3535

36-
func (w *wrappedResourceProviderClient) ListComplete(ctx context.Context, filter string) (compute.ResourceSkusResultIterator, error) {
37-
page, err := w.client.List(ctx, filter)
36+
//nolint:lll
37+
func (w *wrappedResourceProviderClient) ListComplete(ctx context.Context, filter, includeExtendedLocations string) (compute.ResourceSkusResultIterator, error) {
38+
page, err := w.client.List(ctx, filter, includeExtendedLocations)
3839
if err != nil {
3940
return compute.ResourceSkusResultIterator{}, nil
4041
}
4142
return compute.NewResourceSkusResultIterator(page), nil
4243
}
4344

44-
type iterFunc func(context.Context, string) (compute.ResourceSkusResultIterator, error)
45+
type iterFunc func(context.Context, string, string) (compute.ResourceSkusResultIterator, error)
4546

4647
// iterate invokes fn to get an iterator, then drains it into an array.
47-
func iterate(ctx context.Context, filter string, fn iterFunc) ([]compute.ResourceSku, error) {
48-
iter, err := fn(ctx, filter)
48+
func iterate(ctx context.Context, filter, includeExtendedLocations string, fn iterFunc) ([]compute.ResourceSku, error) {
49+
iter, err := fn(ctx, filter, includeExtendedLocations)
4950
if err != nil {
5051
return nil, errors.Wrap(err, "could not list resource skus")
5152
}

const.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ const (
4949
// Generation 2.
5050
HyperVGeneration2 = "V2"
5151
)
52+
53+
const (
54+
ten = 10
55+
sixtyFour = 64
56+
)

data_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
"testing"
88

9-
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute"
9+
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute" //nolint:staticcheck
1010
"github.com/google/go-cmp/cmp"
1111
"github.com/google/go-cmp/cmp/cmpopts"
1212
)

fakes_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package skewer
33
import (
44
"context"
55
"encoding/json"
6-
"io/ioutil"
6+
"os"
77

8-
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute"
8+
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute" //nolint:staticcheck
99
)
1010

1111
// dataWrapper is a convenience wrapper for deserializing json testdata
@@ -16,7 +16,7 @@ type dataWrapper struct {
1616
// newDataWrapper takes a path to a list of compute skus and parses them
1717
// to a dataWrapper for use in fake clients
1818
func newDataWrapper(path string) (*dataWrapper, error) {
19-
data, err := ioutil.ReadFile(path)
19+
data, err := os.ReadFile(path)
2020
if err != nil {
2121
return nil, err
2222
}
@@ -36,7 +36,7 @@ type fakeClient struct {
3636
err error
3737
}
3838

39-
func (f *fakeClient) List(ctx context.Context, filter string) ([]compute.ResourceSku, error) {
39+
func (f *fakeClient) List(ctx context.Context, filter, includeExtendedLocations string) ([]compute.ResourceSku, error) {
4040
if f.err != nil {
4141
return nil, f.err
4242
}
@@ -51,7 +51,8 @@ type fakeResourceClient struct {
5151
err error
5252
}
5353

54-
func (f *fakeResourceClient) ListComplete(ctx context.Context, filter string) (compute.ResourceSkusResultIterator, error) {
54+
//nolint:lll
55+
func (f *fakeResourceClient) ListComplete(ctx context.Context, filter, includeExtendedLocations string) (compute.ResourceSkusResultIterator, error) {
5556
if f.err != nil {
5657
return compute.ResourceSkusResultIterator{}, f.err
5758
}
@@ -90,7 +91,8 @@ type fakeResourceProviderClient struct {
9091
err error
9192
}
9293

93-
func (f *fakeResourceProviderClient) List(ctx context.Context, filter string) (compute.ResourceSkusResultPage, error) {
94+
//nolint:lll
95+
func (f *fakeResourceProviderClient) List(ctx context.Context, filter, includeExtendedLocations string) (compute.ResourceSkusResultPage, error) {
9496
if f.err != nil {
9597
return compute.ResourceSkusResultPage{}, f.err
9698
}

go.mod

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/Azure/skewer
22

3-
go 1.13
3+
go 1.17
44

55
require (
66
github.com/Azure/azure-sdk-for-go v66.0.0+incompatible
@@ -10,4 +10,14 @@ require (
1010
github.com/pkg/errors v0.9.1
1111
)
1212

13-
require github.com/Azure/go-autorest/autorest/validation v0.3.0 // indirect
13+
require (
14+
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
15+
github.com/Azure/go-autorest/autorest/adal v0.9.18 // indirect
16+
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
17+
github.com/Azure/go-autorest/autorest/validation v0.3.0 // indirect
18+
github.com/Azure/go-autorest/logger v0.2.1 // indirect
19+
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
20+
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
21+
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
22+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
23+
)

interface.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ package skewer
33
import (
44
"context"
55

6-
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute"
6+
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-12-01/compute" //nolint:staticcheck
77
)
88

99
// ResourceClient is the required Azure client interface used to populate skewer's data.
1010
type ResourceClient interface {
11-
ListComplete(ctx context.Context, filter string) (compute.ResourceSkusResultIterator, error)
11+
ListComplete(ctx context.Context, filter, includeExtendedLocations string) (compute.ResourceSkusResultIterator, error)
1212
}
1313

1414
// ResourceProviderClient is a convenience interface for uses cases
1515
// specific to Azure resource providers.
1616
type ResourceProviderClient interface {
17-
List(ctx context.Context, filter string) (compute.ResourceSkusResultPage, error)
17+
List(ctx context.Context, filter, includeExtendedLocations string) (compute.ResourceSkusResultPage, error)
1818
}
1919

2020
// client defines the internal interface required by the skewer Cache.
2121
// TODO(ace): implement a lazy iterator with caching (and a cursor?)
2222
type client interface {
23-
List(ctx context.Context, filter string) ([]compute.ResourceSku, error)
23+
List(ctx context.Context, filter, includeExtendedLocations string) ([]compute.ResourceSku, error)
2424
}

0 commit comments

Comments
 (0)