-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from CecileRobertMichon/services-tests
Refactor services and Azure clients to make services unit testable
- Loading branch information
Showing
70 changed files
with
2,153 additions
and
2,042 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package availabilityzones | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" | ||
"github.com/Azure/go-autorest/autorest" | ||
azure "sigs.k8s.io/cluster-api-provider-azure/cloud" | ||
) | ||
|
||
// Client wraps go-sdk | ||
type Client interface { | ||
ListComplete(context.Context) (compute.ResourceSkusResultIterator, error) | ||
} | ||
|
||
// AzureClient contains the Azure go-sdk Client | ||
type AzureClient struct { | ||
resourceSkus compute.ResourceSkusClient | ||
} | ||
|
||
var _ Client = &AzureClient{} | ||
|
||
// NewClient creates a new VM client from subscription ID. | ||
func NewClient(subscriptionID string, authorizer autorest.Authorizer) *AzureClient { | ||
c := newResourceSkusClient(subscriptionID, authorizer) | ||
return &AzureClient{c} | ||
} | ||
|
||
// getResourceSkusClient creates a new availability zones client from subscription ID. | ||
func newResourceSkusClient(subscriptionID string, authorizer autorest.Authorizer) compute.ResourceSkusClient { | ||
skusClient := compute.NewResourceSkusClient(subscriptionID) | ||
skusClient.Authorizer = authorizer | ||
skusClient.AddToUserAgent(azure.UserAgent) | ||
return skusClient | ||
} | ||
|
||
// ListComplete enumerates all values, automatically crossing page boundaries as required. | ||
func (ac *AzureClient) ListComplete(ctx context.Context) (compute.ResourceSkusResultIterator, error) { | ||
return ac.resourceSkus.ListComplete(ctx) | ||
} |
41 changes: 20 additions & 21 deletions
41
cloud/services/availabilityzones/mock_availabilityzones/availabilityzones_mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
cloud/services/availabilityzones/mock_availabilityzones/doc.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Run go generate to regenerate this mock. | ||
//go:generate ../../../../hack/tools/bin/mockgen -destination availabilityzones_mock.go -package mock_availabilityzones -source ../client.go Client | ||
//go:generate /usr/bin/env bash -c "cat ../../../../hack/boilerplate/boilerplate.generatego.txt availabilityzones_mock.go > _availabilityzones_mock.go && mv _availabilityzones_mock.go availabilityzones_mock.go" | ||
|
||
package mock_availabilityzones //nolint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package disks | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" | ||
"github.com/Azure/go-autorest/autorest" | ||
azure "sigs.k8s.io/cluster-api-provider-azure/cloud" | ||
) | ||
|
||
// Client wraps go-sdk | ||
type Client interface { | ||
Delete(context.Context, string, string) error | ||
} | ||
|
||
// AzureClient contains the Azure go-sdk Client | ||
type AzureClient struct { | ||
disks compute.DisksClient | ||
} | ||
|
||
var _ Client = &AzureClient{} | ||
|
||
// NewClient creates a new VM client from subscription ID. | ||
func NewClient(subscriptionID string, authorizer autorest.Authorizer) *AzureClient { | ||
c := newDisksClient(subscriptionID, authorizer) | ||
return &AzureClient{c} | ||
} | ||
|
||
// newDisksClient creates a new disks client from subscription ID. | ||
func newDisksClient(subscriptionID string, authorizer autorest.Authorizer) compute.DisksClient { | ||
disksClient := compute.NewDisksClient(subscriptionID) | ||
disksClient.Authorizer = authorizer | ||
disksClient.AddToUserAgent(azure.UserAgent) | ||
return disksClient | ||
} | ||
|
||
func (ac *AzureClient) Delete(ctx context.Context, resourceGroupName, name string) error { | ||
future, err := ac.disks.Delete(ctx, resourceGroupName, name) | ||
if err != nil { | ||
return err | ||
} | ||
err = future.WaitForCompletionRef(ctx, ac.disks.Client) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = future.Result(ac.disks) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.