Skip to content

Commit

Permalink
Add mock interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <[email protected]>
  • Loading branch information
justaugustus committed Apr 16, 2019
1 parent 0345fdf commit db8af50
Show file tree
Hide file tree
Showing 73 changed files with 3,482 additions and 888 deletions.
21 changes: 20 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
# unused-packages = true

required = [
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-03-01/compute/computeapi",
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network/networkapi",
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources/resourcesapi",
"github.com/Azure/go-autorest/autorest",
"github.com/golang/mock/gomock",
"github.com/golang/mock/mockgen/model",
"github.com/emicklei/go-restful",
"github.com/onsi/ginkgo", # for test framework
"github.com/onsi/gomega", # for test matchers
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,11 @@ dep-ensure: check-install ## Ensure dependencies are up to date
gazelle: ## Run Bazel Gazelle
bazel run //:gazelle $(BAZEL_ARGS)

# TODO: Uncomment mock generation once mocks exist
.PHONY: generate
generate: ## Generate mocks, CRDs and runs `go generate` through Bazel
GOPATH=$(shell go env GOPATH) bazel run //:generate $(BAZEL_ARGS)
$(MAKE) dep-ensure
$(MAKE) generate-deepcopy
# bazel build $(BAZEL_ARGS) //pkg/cloud/azure/services/mocks:go_mock_interfaces \
# //pkg/cloud/azure/services/ec2/mock_ec2iface:go_default_library \
# //pkg/cloud/azure/services/elb/mock_elbiface:go_default_library
# cp -Rf bazel-genfiles/pkg/* pkg/
$(MAKE) generate-crds

.PHONY: generate-deepcopy
Expand Down
7 changes: 6 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

http_archive(
name = "io_bazel_rules_go",
Expand Down Expand Up @@ -96,6 +95,12 @@ go_repository(
tag = "v1.2.0",
)

go_repository(
name = "bazel_gomock",
commit = "08cc809a2f68f6d810c2013987970a9a5c1181b4",
importpath = "github.com/jmhodges/bazel_gomock",
)

go_repository(
name = "io_k8s_sigs_kind",
commit = "161151a26faf0dbe962ac9f323cc0cdebac79ba8",
Expand Down
14 changes: 0 additions & 14 deletions build/asmshim/BUILD

This file was deleted.

21 changes: 0 additions & 21 deletions build/asmshim/c.go

This file was deleted.

34 changes: 0 additions & 34 deletions build/asmshim/textflag.h

This file was deleted.

91 changes: 0 additions & 91 deletions build/go_mock.bzl

This file was deleted.

30 changes: 30 additions & 0 deletions hack/copy-bazel-mocks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# 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.

set -o errexit
set -o nounset
set -o pipefail

REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
cd "${REPO_ROOT}" || exit 1

BOILERPLATE=$(sed "s/YEAR/$(date +%Y)/g" < hack/boilerplate/boilerplate.go.txt)

while IFS= read -r -d '' file
do
out=$(echo "${file}" | sed "s#bazel-bin/##g")
echo -e "${BOILERPLATE}\n" > "${out}"
cat "${file}" >> "${out}"
done < <(find bazel-bin/pkg -name '*_mock.go' -type f -print0)
4 changes: 4 additions & 0 deletions pkg/apis/azureprovider/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ResourceSpec defines a generic spec that can used to define Azure resources.
// TODO: ResourceSpec should be removed once concrete specs have been defined for all Azure resources in use.
type ResourceSpec interface{}

// TODO: Write type tests

// AzureResourceReference is a reference to a specific Azure resource by ID
Expand Down
5 changes: 4 additions & 1 deletion pkg/cloud/azure/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ go_library(
],
importpath = "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure",
visibility = ["//visibility:public"],
deps = ["//vendor/github.com/Azure/go-autorest/autorest:go_default_library"],
deps = [
"//pkg/apis/azureprovider/v1alpha1:go_default_library",
"//vendor/github.com/Azure/go-autorest/autorest:go_default_library",
],
)
18 changes: 9 additions & 9 deletions pkg/cloud/azure/actuators/machine/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ type FakeVMService struct {
}

// Get returns fake success.
func (s *FakeVMService) Get(ctx context.Context, spec azure.Spec) (interface{}, error) {
func (s *FakeVMService) Get(ctx context.Context, spec v1alpha1.ResourceSpec) (interface{}, error) {
s.GetCallCount++
return compute.VirtualMachine{
ID: to.StringPtr(s.ID),
Expand All @@ -206,13 +206,13 @@ func (s *FakeVMService) Get(ctx context.Context, spec azure.Spec) (interface{},
}

// Reconcile returns fake success.
func (s *FakeVMService) Reconcile(ctx context.Context, spec azure.Spec) error {
func (s *FakeVMService) Reconcile(ctx context.Context, spec v1alpha1.ResourceSpec) error {
s.CreateOrUpdateCallCount++
return nil
}

// Delete returns fake success.
func (s *FakeVMService) Delete(ctx context.Context, spec azure.Spec) error {
func (s *FakeVMService) Delete(ctx context.Context, spec v1alpha1.ResourceSpec) error {
s.DeleteCallCount++
return nil
}
Expand Down Expand Up @@ -381,12 +381,12 @@ type FakeVMCheckZonesService struct {
}

// Get returns fake success.
func (s *FakeVMCheckZonesService) Get(ctx context.Context, spec azure.Spec) (interface{}, error) {
func (s *FakeVMCheckZonesService) Get(ctx context.Context, spec v1alpha1.ResourceSpec) (interface{}, error) {
return nil, errors.New("vm not found")
}

// Reconcile returns fake success.
func (s *FakeVMCheckZonesService) Reconcile(ctx context.Context, spec azure.Spec) error {
func (s *FakeVMCheckZonesService) Reconcile(ctx context.Context, spec v1alpha1.ResourceSpec) error {
vmSpec, ok := spec.(*virtualmachines.Spec)
if !ok {
return errors.New("invalid vm specification")
Expand All @@ -405,7 +405,7 @@ func (s *FakeVMCheckZonesService) Reconcile(ctx context.Context, spec azure.Spec
}

// Delete returns fake success.
func (s *FakeVMCheckZonesService) Delete(ctx context.Context, spec azure.Spec) error {
func (s *FakeVMCheckZonesService) Delete(ctx context.Context, spec v1alpha1.ResourceSpec) error {
return nil
}

Expand All @@ -415,17 +415,17 @@ type FakeAvailabilityZonesService struct {
}

// Get returns fake success.
func (s *FakeAvailabilityZonesService) Get(ctx context.Context, spec azure.Spec) (interface{}, error) {
func (s *FakeAvailabilityZonesService) Get(ctx context.Context, spec v1alpha1.ResourceSpec) (interface{}, error) {
return s.zonesResponse, nil
}

// Reconcile returns fake success.
func (s *FakeAvailabilityZonesService) Reconcile(ctx context.Context, spec azure.Spec) error {
func (s *FakeAvailabilityZonesService) Reconcile(ctx context.Context, spec v1alpha1.ResourceSpec) error {
return nil
}

// Delete returns fake success.
func (s *FakeAvailabilityZonesService) Delete(ctx context.Context, spec azure.Spec) error {
func (s *FakeAvailabilityZonesService) Delete(ctx context.Context, spec v1alpha1.ResourceSpec) error {
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/cloud/azure/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (
DefaultInternalLBIPAddress = "10.0.0.100"
// DefaultAzureDNSZone is the default provided azure dns zone
DefaultAzureDNSZone = "cloudapp.azure.com"
// UserAgent used for communicating with azure
UserAgent = "cluster-api-azure-services"
)

// GenerateVnetName generates a virtual network name, based on the cluster name.
Expand Down
Loading

0 comments on commit db8af50

Please sign in to comment.