Skip to content

Commit f7600aa

Browse files
uwefreidankTheBigElmoRalfHammer
authored
Add unit and integration test environment (#44)
* add test environment add 1st unit test add 1st integration test * add license header * Delete unnecessarily docu * revert build.yaml * add license header to counterfeiter generating * add license header * remove duplicate constants * check metrics port * remove netstat * try metrics-port 8088 * disable test in dockerfile * disable metrics for envtest * revert removal of envtest in dockerfile --------- Co-authored-by: TheBigElmo <50952498+TheBigElmo@users.noreply.github.com> Co-authored-by: d039803 <ralf.hammer@sap.com>
1 parent 1b9252b commit f7600aa

13 files changed

Lines changed: 1858 additions & 127 deletions

File tree

.vscode/launch.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
"--cluster-resource-namespace=default",
1818
"--sap-binding-metadata"
1919
]
20-
}
20+
},
21+
{
22+
"name": "Run integration test",
23+
"type": "go",
24+
"request": "launch",
25+
"mode": "test",
26+
"program": "${workspaceFolder}/internal/controllers",
27+
"console": "internalConsole",
28+
"env": {
29+
"KUBEBUILDER_ASSETS": "${workspaceFolder}/bin/k8s/current",
30+
},
31+
"args": [],
32+
"showLog": true
33+
},
2134
]
2235
}

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
4444
rm -rf crds && cp -r config/crd/bases crds
4545

4646
.PHONY: generate
47-
generate: controller-gen client-gen informer-gen lister-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
47+
generate: controller-gen client-gen informer-gen lister-gen counterfeiter-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
4848
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
49+
PATH="$(PATH):$(LOCALBIN)" go generate ./...
4950
./hack/gen-typed-client
5051

5152
.PHONY: fmt
@@ -60,6 +61,10 @@ vet: ## Run go vet against code.
6061
test: manifests generate fmt vet envtest ## Run tests.
6162
KUBEBUILDER_ASSETS="$(LOCALBIN)/k8s/current" go test ./... -coverprofile cover.out
6263

64+
.PHONY: test-fast ## Run tests without build.
65+
test-fast: envtest ## Run tests.
66+
KUBEBUILDER_ASSETS="$(LOCALBIN)/k8s/current" go test ./... -coverprofile cover.out -ginkgo.v
67+
6368
##@ Build
6469

6570
.PHONY: build
@@ -131,6 +136,7 @@ $(LOCALBIN):
131136
## Tool Binaries
132137
KUSTOMIZE ?= $(LOCALBIN)/kustomize
133138
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
139+
COUNTERFEITER_GEN ?= $(LOCALBIN)/counterfeiter-gen
134140
ENVTEST ?= $(LOCALBIN)/setup-envtest
135141
CLIENT_GEN ?= $(shell pwd)/bin/client-gen
136142
INFORMER_GEN ?= $(shell pwd)/bin/informer-gen
@@ -140,6 +146,7 @@ LISTER_GEN ?= $(shell pwd)/bin/lister-gen
140146
KUSTOMIZE_VERSION ?= v3.8.7
141147
CONTROLLER_TOOLS_VERSION ?= v0.9.2
142148
CODE_GENERATOR_VERSION ?= v0.23.4
149+
COUNTERFEITER_VERSION ?= v6.8.1
143150

144151
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
145152
.PHONY: kustomize
@@ -152,6 +159,11 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
152159
$(CONTROLLER_GEN): $(LOCALBIN)
153160
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
154161

162+
.PHONY: counterfeiter-gen
163+
counterfeiter-gen: $(COUNTERFEITER_GEN) ## Download controller-gen locally if necessary.
164+
$(COUNTERFEITER_GEN): $(LOCALBIN)
165+
test -s $(COUNTERFEITER_GEN) || GOBIN=$(LOCALBIN) go install github.com/maxbrunsfeld/counterfeiter/v6@$(COUNTERFEITER_VERSION)
166+
155167
.PHONY: envtest
156168
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
157169
$(ENVTEST): $(LOCALBIN)

go.mod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ go 1.21
44

55
require (
66
github.com/cloudfoundry-community/go-cfclient/v3 v3.0.0-alpha.5
7+
github.com/maxbrunsfeld/counterfeiter/v6 v6.8.1
8+
github.com/onsi/ginkgo/v2 v2.15.0
9+
github.com/onsi/gomega v1.31.1
710
github.com/pkg/errors v0.9.1
811
k8s.io/api v0.29.0
912
k8s.io/apiextensions-apiserver v0.29.0
@@ -27,19 +30,20 @@ require (
2730
github.com/go-openapi/jsonpointer v0.19.6 // indirect
2831
github.com/go-openapi/jsonreference v0.20.2 // indirect
2932
github.com/go-openapi/swag v0.22.3 // indirect
33+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
3034
github.com/gogo/protobuf v1.3.2 // indirect
3135
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3236
github.com/golang/protobuf v1.5.3 // indirect
3337
github.com/google/gnostic-models v0.6.8 // indirect
3438
github.com/google/go-cmp v0.6.0 // indirect
3539
github.com/google/gofuzz v1.2.0 // indirect
40+
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
3641
github.com/google/uuid v1.3.0 // indirect
3742
github.com/imdario/mergo v0.3.12 // indirect
3843
github.com/josharian/intern v1.0.0 // indirect
3944
github.com/json-iterator/go v1.1.12 // indirect
4045
github.com/mailru/easyjson v0.7.7 // indirect
4146
github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11 // indirect
42-
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
4347
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
4448
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4549
github.com/modern-go/reflect2 v1.0.2 // indirect
@@ -55,12 +59,14 @@ require (
5559
go.uber.org/multierr v1.11.0 // indirect
5660
go.uber.org/zap v1.26.0 // indirect
5761
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
58-
golang.org/x/net v0.19.0 // indirect
62+
golang.org/x/mod v0.14.0 // indirect
63+
golang.org/x/net v0.20.0 // indirect
5964
golang.org/x/oauth2 v0.12.0 // indirect
6065
golang.org/x/sys v0.16.0 // indirect
61-
golang.org/x/term v0.15.0 // indirect
66+
golang.org/x/term v0.16.0 // indirect
6267
golang.org/x/text v0.14.0 // indirect
6368
golang.org/x/time v0.3.0 // indirect
69+
golang.org/x/tools v0.17.0 // indirect
6470
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
6571
google.golang.org/appengine v1.6.7 // indirect
6672
google.golang.org/protobuf v1.31.0 // indirect

0 commit comments

Comments
 (0)