Skip to content

Commit debdcc2

Browse files
Merge pull request #323 from Nikokolas3270/OSD-25983
OSD-25983: making sure that the Makefile installs the tools needed by the various targets or at least display a meaningful error if some tool is not installed
2 parents b3b8b85 + 893aba1 commit debdcc2

File tree

6 files changed

+70
-42
lines changed

6 files changed

+70
-42
lines changed

Makefile

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
include project.mk
22
include boilerplate/generated-includes.mk
33

4-
GOLANGCI_LINT_VERSION=v1.58.1
4+
GOLANGCI_LINT_VERSION=v1.59.1
5+
MOCKGEN_VERSION=v0.5.0
56

67
.DEFAULT_GOAL := all
78

@@ -16,30 +17,30 @@ all: interceptor cadctl template-updater generate-template-file ## Generate, bu
1617
build: build-interceptor build-cadctl build-template-updater ## Build all subprojects in this repository
1718

1819
.PHONY: lint
19-
lint: getlint lint-cadctl lint-interceptor lint-template-updater ## Lint all subprojects
20+
lint: lint-cadctl lint-interceptor lint-template-updater ## Lint all subprojects
2021

2122
##@ cadctl:
2223
.PHONY: cadctl
2324
cadctl: generate-cadctl build-cadctl test-cadctl lint-cadctl generate-template-file ## Run all targets for cadctl (generate, build, test, lint, generation)
2425

2526
.PHONY: generate-cadctl
26-
generate-cadctl: ## Generate mocks for cadctl
27+
generate-cadctl: check-go121-install install-mockgen ## Generate mocks for cadctl
2728
go generate -mod=readonly ./...
2829

2930
.PHONY: build-cadctl
30-
build-cadctl: ## Build the cadctl binary
31+
build-cadctl: check-go121-install ## Build the cadctl binary
3132
@echo
3233
@echo "Building cadctl..."
3334
cd cadctl && go build -ldflags="-s -w" -mod=readonly -trimpath -o ../bin/cadctl .
3435

3536
.PHONY: lint-cadctl
36-
lint-cadctl: ## Lint cadctl subproject
37+
lint-cadctl: install-linter ## Lint cadctl subproject
3738
@echo
3839
@echo "Linting cadctl..."
3940
GOLANGCI_LINT_CACHE=$$(mktemp -d) $(GOPATH)/bin/golangci-lint run -c .golangci.yml
4041

4142
.PHONY: test-cadctl
42-
test-cadctl: ## Run automated tests for cadctl
43+
test-cadctl: check-go121-install ## Run automated tests for cadctl
4344
@echo
4445
@echo "Running unit tests for cadctl..."
4546
go test $(TESTOPTS) -race -mod=readonly ./cadctl/... ./pkg/...
@@ -49,19 +50,19 @@ test-cadctl: ## Run automated tests for cadctl
4950
interceptor: build-interceptor test-interceptor lint-interceptor ## Run all targets for interceptor (build, test, lint)
5051

5152
.PHONY: build-interceptor
52-
build-interceptor: ## Build the interceptor binary
53+
build-interceptor: check-go121-install ## Build the interceptor binary
5354
@echo
5455
@echo "Building interceptor..."
5556
cd interceptor && go build -ldflags="-s -w" -mod=readonly -trimpath -o ../bin/interceptor .
5657

5758
.PHONY: lint-interceptor
58-
lint-interceptor: ## Lint interceptor subproject
59+
lint-interceptor: install-linter ## Lint interceptor subproject
5960
@echo
6061
@echo "Linting interceptor..."
6162
cd interceptor && GOLANGCI_LINT_CACHE=$$(mktemp -d) $(GOPATH)/bin/golangci-lint run -c ../.golangci.yml
6263

6364
.PHONY: test-interceptor
64-
test-interceptor: build-interceptor ## Run automated tests for interceptor
65+
test-interceptor: check-go121-install check-jq-install check-vault-install build-interceptor ## Run automated tests for interceptor
6566
@echo
6667
@echo "Running unit tests for interceptor..."
6768
cd interceptor && go test -race -mod=readonly ./...
@@ -80,7 +81,7 @@ build-template-updater: ## Build the template-updater binary
8081
cd hack/update-template && go build -ldflags="-s -w" -mod=readonly -trimpath -o ../../bin/template-updater .
8182

8283
.PHONY: lint-template-updater
83-
lint-template-updater: ## Lint template-updater subproject
84+
lint-template-updater: install-linter ## Lint template-updater subproject
8485
@echo
8586
@echo "Linting template-updater..."
8687
cd hack/update-template && GOLANGCI_LINT_CACHE=$$(mktemp -d) $(GOPATH)/bin/golangci-lint run -c ../../.golangci.yml
@@ -95,15 +96,29 @@ generate-template-file: build-template-updater ## Generate deploy template file
9596
@echo "Generating template file..."
9697
cp ./bin/template-updater ./hack/update-template/ && cd ./hack/update-template/ && ./template-updater
9798

98-
# Installed using instructions from: https://golangci-lint.run/usage/install/#linux-and-windows
99-
getlint:
100-
@mkdir -p $(GOPATH)/bin
101-
@ls $(GOPATH)/bin/golangci-lint 1>/dev/null || (echo "Installing golangci-lint..." && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin $(GOLANGCI_LINT_VERSION))
102-
10399
### CI Only
104100
.PHONY: coverage
105101
coverage:
106102
hack/codecov.sh
107103

108104
.PHONY: validate
109105
validate: generate-template-file isclean
106+
107+
### Prerequisites
108+
### It is assumed that 'make' is already installed
109+
### Version of go is checked but the version the tools are not checked as this should not matter much.
110+
.PHONY: check-%-install
111+
check-%-install:
112+
@type $* 1> /dev/null || (>&2 echo && echo "'$*' IS NOT INSTALLED - install it manually" && echo && false)
113+
114+
.PHONY: check-go121-install
115+
check-go121-install:
116+
@(type go 1> /dev/null && go version | grep -q 'go[1-9].[2-9][1-9]') || (>&2 echo && echo "'go' WITH VERSION >= 1.21 IS NOT INSTALLED - install it manually" && echo && false)
117+
118+
.PHONY: install-linter
119+
install-linter: check-curl-install check-go121-install
120+
@ls $(GOPATH)/bin/golangci-lint 1>/dev/null || (echo && echo "Installing 'golangci-lint'..." && mkdir -p $(GOPATH)/bin && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin $(GOLANGCI_LINT_VERSION))
121+
122+
.PHONY: install-mockgen
123+
install-mockgen: check-go121-install
124+
@type mockgen 1> /dev/null || (echo && echo "Installing 'mockgen'..." && go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION))

interceptor/test/e2e.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,38 @@ function test_interceptor {
2424
INTERCEPTOR_PID=$!
2525

2626
# Wait for 1 second to allow the interceptor to start up
27-
sleep 1
27+
sleep 5
2828

2929
local incident_id=$1
3030
local expected_response=$2
3131

3232
# Send an interceptor request to localhost:8080
3333
# See https://pkg.go.dev/github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1#InterceptorRequest
34+
CURL_EXITCODE=0
3435
CURL_OUTPUT=$(curl -s -X POST -H "Content-Type: application/json" \
3536
-d "{\"body\":\"{\\\"__pd_metadata\\\":{\\\"incident\\\":{\\\"id\\\":\\\"$incident_id\\\"}}}\",\"header\":{\"Content-Type\":[\"application/json\"]},\"extensions\":{},\"interceptor_params\":{},\"context\":null}" \
36-
http://localhost:8080)
37+
http://localhost:8080) || CURL_EXITCODE=$?
3738

3839
# Check if the curl output matches the expected response
39-
if [[ "$CURL_OUTPUT" == "$expected_response" ]]; then
40+
if [[ "$CURL_OUTPUT" == "$expected_response" ]] && [[ "$CURL_EXITCODE" == "0" ]]; then
4041
echo -e "${GREEN}Test passed for incident ID $incident_id: Response is as expected.${NC}"
42+
43+
# Shut down the interceptor
44+
kill $INTERCEPTOR_PID
4145
else
4246
echo -e "${RED}Test failed for incident ID $incident_id: Unexpected response.${NC}"
4347
echo -e "${RED}Expected: $expected_response${NC}"
4448
echo -e "${RED}Got: $CURL_OUTPUT${NC}"
49+
echo -e "${RED}Exit code: $CURL_EXITCODE${NC}"
4550
echo -e ""
4651
echo -e "Interceptor logs"
4752
cat $temp_log_file
48-
fi
4953

50-
# Shut down the interceptor
51-
kill $INTERCEPTOR_PID
54+
# Shut down the interceptor
55+
kill $INTERCEPTOR_PID
56+
57+
return 1
58+
fi
5259
}
5360

5461
# Expected outputs

pkg/aws/mock/aws.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ocm/mock/ocmmock.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/pagerduty/mock/pagerdutymock.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/pagerduty/pagerduty_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var _ = Describe("Pagerduty", func() {
3131
// each startup of PagerDuty we need to verify the user's email for future requests
3232
mux.HandleFunc("/users/me", func(w http.ResponseWriter, r *http.Request) {
3333
Expect(r.Method).Should(Equal("GET"))
34-
fmt.Fprint(w, `{"user":{"email":"[email protected]"}}`)
34+
_, _ = fmt.Fprint(w, `{"user":{"email":"[email protected]"}}`)
3535
})
3636
var err error // err is declared to make clear the p is not created here, but is global
3737
p, err = pagerduty.NewWithToken(
@@ -71,7 +71,7 @@ var _ = Describe("Pagerduty", func() {
7171
Expect(r.Method).Should(Equal("PUT"))
7272
w.Header().Set("Content-Type", "application/json")
7373
w.WriteHeader(http.StatusBadRequest)
74-
fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
74+
_, _ = fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
7575
})
7676
// Act
7777
err := p.MoveToEscalationPolicy(escalationPolicyID)
@@ -87,7 +87,7 @@ var _ = Describe("Pagerduty", func() {
8787
// Arrange
8888
mux.HandleFunc("/incidents", func(w http.ResponseWriter, r *http.Request) {
8989
Expect(r.Method).Should(Equal("PUT"))
90-
fmt.Fprint(w, `{}`)
90+
_, _ = fmt.Fprint(w, `{}`)
9191
})
9292
// Act
9393
err := p.MoveToEscalationPolicy(escalationPolicyID)
@@ -124,7 +124,7 @@ var _ = Describe("Pagerduty", func() {
124124
Expect(r.Method).Should(Equal("PUT"))
125125
w.Header().Set("Content-Type", "application/json")
126126
w.WriteHeader(http.StatusBadRequest)
127-
fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
127+
_, _ = fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
128128
})
129129
// Act
130130
err := p.AssignToUser(userID)
@@ -140,7 +140,7 @@ var _ = Describe("Pagerduty", func() {
140140
// Arrange
141141
mux.HandleFunc("/incidents", func(w http.ResponseWriter, r *http.Request) {
142142
Expect(r.Method).Should(Equal("PUT"))
143-
fmt.Fprint(w, `{}`)
143+
_, _ = fmt.Fprint(w, `{}`)
144144
})
145145
// Act
146146
err := p.AssignToUser(userID)
@@ -175,7 +175,7 @@ var _ = Describe("Pagerduty", func() {
175175
Expect(r.Method).Should(Equal("PUT"))
176176
w.Header().Set("Content-Type", "application/json")
177177
w.WriteHeader(http.StatusBadRequest)
178-
fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
178+
_, _ = fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
179179
})
180180
// Act
181181
err := p.AcknowledgeIncident()
@@ -191,7 +191,7 @@ var _ = Describe("Pagerduty", func() {
191191
// Arrange
192192
mux.HandleFunc("/incidents", func(w http.ResponseWriter, r *http.Request) {
193193
Expect(r.Method).Should(Equal("PUT"))
194-
fmt.Fprint(w, `{}`)
194+
_, _ = fmt.Fprint(w, `{}`)
195195
})
196196
// Act
197197
err := p.AcknowledgeIncident()
@@ -216,7 +216,7 @@ var _ = Describe("Pagerduty", func() {
216216
Expect(r.Method).Should(Equal("POST"))
217217
w.Header().Set("Content-Type", "application/json")
218218
w.WriteHeader(http.StatusUnauthorized)
219-
fmt.Fprint(w, `{}`)
219+
_, _ = fmt.Fprint(w, `{}`)
220220
})
221221
// Act
222222
err := p.AddNote(noteContent)
@@ -233,7 +233,7 @@ var _ = Describe("Pagerduty", func() {
233233
Expect(r.Method).Should(Equal("POST"))
234234
w.Header().Set("Content-Type", "application/json")
235235
w.WriteHeader(http.StatusBadRequest)
236-
fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
236+
_, _ = fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
237237
})
238238
// Act
239239
err := p.AddNote(noteContent)
@@ -264,7 +264,7 @@ var _ = Describe("Pagerduty", func() {
264264
// Arrange
265265
mux.HandleFunc(fmt.Sprintf("/incidents/%s/notes", incidentID), func(w http.ResponseWriter, r *http.Request) {
266266
Expect(r.Method).Should(Equal("POST"))
267-
fmt.Fprint(w, `{}`)
267+
_, _ = fmt.Fprint(w, `{}`)
268268
})
269269
// Act
270270
err := p.AddNote(noteContent)
@@ -286,7 +286,7 @@ var _ = Describe("Pagerduty", func() {
286286
Expect(r.Method).Should(Equal("GET"))
287287
w.Header().Set("Content-Type", "application/json")
288288
w.WriteHeader(http.StatusUnauthorized)
289-
fmt.Fprint(w, `{}`)
289+
_, _ = fmt.Fprint(w, `{}`)
290290
})
291291
// Act
292292
_, err := p.GetAlertsForIncident(incidentID)
@@ -303,7 +303,7 @@ var _ = Describe("Pagerduty", func() {
303303
Expect(r.Method).Should(Equal("GET"))
304304
w.Header().Set("Content-Type", "application/json")
305305
w.WriteHeader(http.StatusBadRequest)
306-
fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
306+
_, _ = fmt.Fprintf(w, `{"error":{"code":%d}}`, pagerduty.InvalidInputParamsErrorCode)
307307
})
308308
// Act
309309
_, err := p.GetAlertsForIncident(incidentID)
@@ -321,7 +321,7 @@ var _ = Describe("Pagerduty", func() {
321321
Expect(r.Method).Should(Equal("GET"))
322322
w.Header().Set("Content-Type", "application/json")
323323
w.WriteHeader(http.StatusNotFound)
324-
fmt.Fprint(w, `{}`)
324+
_, _ = fmt.Fprint(w, `{}`)
325325
})
326326
// Act
327327
_, err := p.GetAlertsForIncident(incidentID)
@@ -337,7 +337,7 @@ var _ = Describe("Pagerduty", func() {
337337
// Arrange
338338
mux.HandleFunc(fmt.Sprintf("/incidents/%s/alerts", incidentID), func(w http.ResponseWriter, r *http.Request) {
339339
// CHGM format of
340-
fmt.Fprint(w, `{"alerts":[{"id":"123456","body":{"details":{"cluster_id": "123456"}}}]}`)
340+
_, _ = fmt.Fprint(w, `{"alerts":[{"id":"123456","body":{"details":{"cluster_id": "123456"}}}]}`)
341341
})
342342
// Act
343343
res, err1 := p.GetAlertsForIncident(incidentID)
@@ -382,7 +382,7 @@ var _ = Describe("Pagerduty", func() {
382382
When("The service has no Dead Man's Snitch integrations", func() {
383383
It("should return an IntegrationNotFoundError", func() {
384384
mux.HandleFunc(fmt.Sprintf("/services/%s", serviceID), func(w http.ResponseWriter, r *http.Request) {
385-
fmt.Fprintf(w, `{"service":{"id":"%s","integrations":[]}}`, serviceID)
385+
_, _ = fmt.Fprintf(w, `{"service":{"id":"%s","integrations":[]}}`, serviceID)
386386
})
387387
err := p.CreateNewAlert(newAlert, serviceID)
388388
Expect(err).To(HaveOccurred())
@@ -392,10 +392,10 @@ var _ = Describe("Pagerduty", func() {
392392
When("The event creation fails", func() {
393393
It("should return a CreateEventError", func() {
394394
mux.HandleFunc(fmt.Sprintf("/services/%s", serviceID), func(w http.ResponseWriter, r *http.Request) {
395-
fmt.Fprintf(w, `{"service":{"id":"%s","integrations":[{"id":"%s"}]}}`, serviceID, dmsIntegrationID)
395+
_, _ = fmt.Fprintf(w, `{"service":{"id":"%s","integrations":[{"id":"%s"}]}}`, serviceID, dmsIntegrationID)
396396
})
397397
mux.HandleFunc(fmt.Sprintf("/services/%s/integrations/%s", serviceID, dmsIntegrationID), func(w http.ResponseWriter, r *http.Request) {
398-
fmt.Fprintf(w, `{"integration":{"id":"%s","name":"%s"}}`, dmsIntegrationID, pagerduty.CADIntegrationName)
398+
_, _ = fmt.Fprintf(w, `{"integration":{"id":"%s","name":"%s"}}`, dmsIntegrationID, pagerduty.CADIntegrationName)
399399
})
400400
err := p.CreateNewAlert(newAlert, serviceID)
401401
Expect(err).To(HaveOccurred())
@@ -481,7 +481,7 @@ var _ = Describe("Pagerduty", func() {
481481
// Arrange
482482
mux.HandleFunc(fmt.Sprintf("/incidents/%s/alerts", incidentID), func(w http.ResponseWriter, r *http.Request) {
483483
// Standard alert format of
484-
fmt.Fprint(w, `{"alerts":[{"id":"1234","body":{"details":{"cluster_id": "654321"}}}]}`)
484+
_, _ = fmt.Fprint(w, `{"alerts":[{"id":"1234","body":{"details":{"cluster_id": "654321"}}}]}`)
485485
})
486486
// Act
487487
res, err := p.RetrieveClusterID()
@@ -495,7 +495,7 @@ var _ = Describe("Pagerduty", func() {
495495
// Arrange
496496
mux.HandleFunc(fmt.Sprintf("/incidents/%s/alerts", incidentID), func(w http.ResponseWriter, r *http.Request) {
497497
// Standard alert format of
498-
fmt.Fprint(w, `{"alerts":[{"id":"1234","body":{"details":{"notes":"cluster_id: 654321"}}}]}`)
498+
_, _ = fmt.Fprint(w, `{"alerts":[{"id":"1234","body":{"details":{"notes":"cluster_id: 654321"}}}]}`)
499499
})
500500
// Act
501501
res, err := p.RetrieveClusterID()
@@ -508,7 +508,7 @@ var _ = Describe("Pagerduty", func() {
508508
It("should raise an error", func() {
509509
mux.HandleFunc(fmt.Sprintf("/incidents/%s/alerts", incidentID), func(w http.ResponseWriter, r *http.Request) {
510510
// Standard alert format of
511-
fmt.Fprint(w, `{"alerts":[{"id":"1234","body":{"describe":{"chicken": 1.75},"steak":true}}]}`)
511+
_, _ = fmt.Fprint(w, `{"alerts":[{"id":"1234","body":{"describe":{"chicken": 1.75},"steak":true}}]}`)
512512
})
513513
// Act
514514
_, err := p.RetrieveClusterID()
@@ -519,7 +519,7 @@ var _ = Describe("Pagerduty", func() {
519519
When("the '.details' field is of the wrong type", func() {
520520
It("should raise an error", func() {
521521
mux.HandleFunc(fmt.Sprintf("/incidents/%s/alerts", incidentID), func(w http.ResponseWriter, r *http.Request) {
522-
fmt.Fprint(w, `{"alerts":[{"id":"1234","body":{"details":"bad details"}}]}`)
522+
_, _ = fmt.Fprint(w, `{"alerts":[{"id":"1234","body":{"details":"bad details"}}]}`)
523523
})
524524

525525
_, err := p.RetrieveClusterID()

0 commit comments

Comments
 (0)