Skip to content

Commit 7a317ff

Browse files
committed
Add tests on scaleway client
1 parent 3e09b01 commit 7a317ff

File tree

18 files changed

+4997
-5
lines changed

18 files changed

+4997
-5
lines changed

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
4646
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4747

4848
.PHONY: generate
49-
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
49+
generate: controller-gen mockgen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
5050
$(CONTROLLER_GEN) object paths="./..."
51+
go generate ./...
5152

5253
.PHONY: fmt
5354
fmt: ## Run go fmt against code.
@@ -59,7 +60,7 @@ vet: ## Run go vet against code.
5960

6061
.PHONY: test
6162
test: manifests generate fmt vet setup-envtest ## Run tests.
62-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
63+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e | grep -v /mock) -coverprofile cover.out
6364

6465
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
6566
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
@@ -189,6 +190,7 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
189190
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
190191
ENVTEST ?= $(LOCALBIN)/setup-envtest
191192
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
193+
MOCKGEN = $(LOCALBIN)/mockgen
192194

193195
## Tool Versions
194196
KUSTOMIZE_VERSION ?= v5.6.0
@@ -198,6 +200,7 @@ ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller
198200
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
199201
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
200202
GOLANGCI_LINT_VERSION ?= v2.1.0
203+
MOCKGEN_VERSION ?= v0.5.2
201204

202205
.PHONY: kustomize
203206
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -227,6 +230,11 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
227230
$(GOLANGCI_LINT): $(LOCALBIN)
228231
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
229232

233+
.PHONY: mockgen
234+
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary.
235+
$(MOCKGEN): $(LOCALBIN)
236+
$(call go-install-tool,$(MOCKGEN),go.uber.org/mock/mockgen,$(MOCKGEN_VERSION))
237+
230238
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
231239
# $1 - target path with name of binary
232240
# $2 - package url which can be installed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/onsi/ginkgo/v2 v2.23.4
77
github.com/onsi/gomega v1.37.0
88
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33
9+
go.uber.org/mock v0.5.2
910
k8s.io/api v0.33.1
1011
k8s.io/apimachinery v0.33.1
1112
k8s.io/client-go v0.33.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
194194
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
195195
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
196196
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
197+
go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko=
198+
go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o=
197199
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
198200
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
199201
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=

internal/service/scaleway/client/block.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ import (
99
"github.com/scaleway/scaleway-sdk-go/scw"
1010
)
1111

12+
type BlockAPI interface {
13+
zonesGetter
14+
15+
UpdateVolume(req *block.UpdateVolumeRequest, opts ...scw.RequestOption) (*block.Volume, error)
16+
ListVolumes(req *block.ListVolumesRequest, opts ...scw.RequestOption) (*block.ListVolumesResponse, error)
17+
DeleteVolume(req *block.DeleteVolumeRequest, opts ...scw.RequestOption) error
18+
}
19+
20+
type BlockClient interface {
21+
UpdateVolumeIOPS(ctx context.Context, zone scw.Zone, volumeID string, iops int64) error
22+
UpdateVolumeTags(ctx context.Context, zone scw.Zone, volumeID string, tags []string) error
23+
FindVolume(ctx context.Context, zone scw.Zone, tags []string) (*block.Volume, error)
24+
DeleteVolume(ctx context.Context, zone scw.Zone, volumeID string) error
25+
}
26+
1227
func (c *Client) UpdateVolumeIOPS(ctx context.Context, zone scw.Zone, volumeID string, iops int64) error {
1328
if err := c.validateZone(c.block, zone); err != nil {
1429
return err

0 commit comments

Comments
 (0)