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 8a48fff
Show file tree
Hide file tree
Showing 84 changed files with 5,480 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
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,25 @@ 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
bazel build $(BAZEL_ARGS) //pkg/cloud/azure/mocks:mocks \
//pkg/cloud/azure/services/availabilityzones/mock_availabilityzones:mocks \
//pkg/cloud/azure/services/groups/mock_groups:mocks \
//pkg/cloud/azure/services/internalloadbalancers/mock_internalloadbalancers:mocks \
//pkg/cloud/azure/services/networkinterfaces/mock_networkinterfaces:mocks \
//pkg/cloud/azure/services/publicips/mock_publicips:mocks \
//pkg/cloud/azure/services/publicloadbalancers/mock_publicloadbalancers:mocks \
//pkg/cloud/azure/services/routetables/mock_routetables:mocks \
//pkg/cloud/azure/services/securitygroups/mock_securitygroups:mocks \
//pkg/cloud/azure/services/subnets/mock_subnets:mocks \
//pkg/cloud/azure/services/virtualmachineextensions/mock_virtualmachineextensions:mocks \
//pkg/cloud/azure/services/virtualmachines/mock_virtualmachines:mocks \
//pkg/cloud/azure/services/virtualnetworks/mock_virtualnetworks:mocks
./hack/copy-bazel-mocks.sh
$(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",
],
)
Loading

0 comments on commit 8a48fff

Please sign in to comment.