This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Makefile
140 lines (111 loc) · 4.6 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# There are four main groups of operations provided by this Makefile: build,
# clean, run and tasks.
# Build operations will create artefacts from code. This includes things such as
# binaries, mock files, or catalogs of CNF tests.
# Clean operations remove the results of the build tasks, or other files not
# considered permanent.
# Run operations provide shortcuts to execute built binaries in common
# configurations or with default options. They are part convenience and part
# documentation.
# Tasks provide shortcuts to common operations that occur frequently during
# development. This includes running configured linters and executing unit tests
GO_PACKAGES=$(shell go list ./... | grep -v vendor)
.PHONY: build \
mocks \
clean \
lint \
test \
coverage-html \
build-cnf-tests \
run-cnf-tests \
run-generic-cnf-tests \
run-container-tests \
run-operator-tests \
run-generic-cnf-tests \
run-operator-tests \
run-container-tests \
clean-mocks \
update-deps \
install-tools \
vet
# Get default value of $GOBIN if not explicitly set
GO_PATH=$(shell go env GOPATH)
ifeq (,$(shell go env GOBIN))
GOBIN=${GO_PATH}/bin
else
GOBIN=$(shell go env GOBIN)
endif
COMMON_GO_ARGS=-race
GIT_COMMIT=$(shell git rev-list -1 HEAD)
GIT_RELEASE=$(shell git tag --points-at HEAD | head -n 1)
GIT_PREVIOUS_RELEASE=$(shell git tag --no-contains HEAD --sort=v:refname | tail -n 1)
GOLANGCI_VERSION=v1.45.2
# Run the unit tests and build all binaries
build:
make test
make build-cnf-tests
build-tnf-tool:
go build -o tnf -v cmd/tnf/main.go
# (Re)generate mock files as needed
mocks: pkg/tnf/interactive/mocks/mock_spawner.go \
pkg/tnf/mocks/mock_tester.go \
pkg/tnf/reel/mocks/mock_reel.go
# Cleans up auto-generated and report files
clean:
go clean
make clean-mocks
rm -f ./test-network-function/test-network-function.test
rm -f ./test-network-function/cnf-certification-tests_junit.xml
rm -f ./tnf
# Run configured linters
lint:
golangci-lint run --timeout 5m0s
# Build and run unit tests
test: mocks
go build ${COMMON_GO_ARGS} ./...
UNIT_TEST="true" go test -coverprofile=cover.out ./...
coverage-html: test
go tool cover -html cover.out
# generate the test catalog in JSON
build-catalog-json: build-tnf-tool
./tnf generate catalog json > catalog.json
# generate the test catalog in Markdown
build-catalog-md: build-tnf-tool
./tnf generate catalog markdown > CATALOG.md
# build the CNF test binary
build-cnf-tests:
PATH=${PATH}:${GOBIN} ginkgo build -ldflags "-X github.com/test-network-function/test-network-function/test-network-function.GitCommit=${GIT_COMMIT} -X github.com/test-network-function/test-network-function/test-network-function.GitRelease=${GIT_RELEASE} -X github.com/test-network-function/test-network-function/test-network-function.GitPreviousRelease=${GIT_PREVIOUS_RELEASE}" ./test-network-function
make build-catalog-md
build-cnf-tests-debug:
PATH=${PATH}:${GOBIN} ginkgo build -gcflags "all=-N -l" -ldflags "-X github.com/test-network-function/test-network-function/test-network-function.GitCommit=${GIT_COMMIT} -X github.com/test-network-function/test-network-function/test-network-function.GitRelease=${GIT_RELEASE} -X github.com/test-network-function/test-network-function/test-network-function.GitPreviousRelease=${GIT_PREVIOUS_RELEASE} -extldflags '-z relro -z now'" ./test-network-function
make build-catalog-md
# Each mock depends on one source file
pkg/tnf/interactive/mocks/mock_spawner.go: pkg/tnf/interactive/spawner.go
mockgen -source=pkg/tnf/interactive/spawner.go -destination=pkg/tnf/interactive/mocks/mock_spawner.go
pkg/tnf/mocks/mock_tester.go: pkg/tnf/test.go
mockgen -source=pkg/tnf/test.go -destination=pkg/tnf/mocks/mock_tester.go
pkg/tnf/reel/mocks/mock_reel.go: pkg/tnf/reel/reel.go
mockgen -source=pkg/tnf/reel/reel.go -destination=pkg/tnf/reel/mocks/mock_reel.go
# Remove generated mock files
clean-mocks:
rm -f pkg/tnf/interactive/mocks/mock_spawner.go
rm -f pkg/tnf/mocks/mock_tester.go
rm -f pkg/tnf/reel/mocks/mock_reel.go
# Update source dependencies and fix versions
update-deps:
make mocks
go mod tidy && \
go mod vendor
# Install build tools and other required software.
install-tools:
go install github.com/onsi/ginkgo/v2/[email protected]
go install github.com/onsi/gomega
go install github.com/golang/mock/[email protected]
wget https://get.helm.sh/helm-v3.8.2-linux-amd64.tar.gz && \
tar -xvf helm-v3.8.2-linux-amd64.tar.gz && \
cp linux-amd64/helm /usr/local/bin/helm
# Install golangci-lint
install-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GO_PATH}/bin ${GOLANGCI_VERSION}
vet:
go vet ${GO_PACKAGES}