Skip to content

Commit 1ee2ac5

Browse files
authored
chore: add e2e coverage (#3425)
1 parent 9807b8e commit 1ee2ac5

File tree

9 files changed

+390
-14
lines changed

9 files changed

+390
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ macos-notary.zip
1717
# Output of the go coverage tool
1818
*.out
1919
coverage.html
20+
cov/
2021

2122
# We don't want to commit the 3rd party notices
2223
third_party_notices/

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
GOLANGCI_VERSION=v1.61.0
44
COVERAGE?=coverage.out
5+
GOCOVERDIR?=$(abspath cov)
56

67
GIT_SHA?=$(shell git rev-parse HEAD)
78

@@ -94,11 +95,11 @@ fix-lint: ## Fix linting errors
9495
check: test fix-lint ## Run tests and linters
9596

9697
.PHONY: check-templates
97-
check-templates:
98+
check-templates: ## Verify templates
9899
go run ./tools/templates-checker
99100

100101
.PHONY: addcopy
101-
addcopy:
102+
addcopy: ## Add missing license to files
102103
@scripts/add-copy.sh
103104

104105
.PHONY: generate
@@ -109,6 +110,10 @@ gen-code: ## Generate code
109110
@echo "==> Generating code"
110111
go run ./tools/cli-generator
111112

113+
.PHONY: otel
114+
otel: ## Generate code
115+
go run ./tools/otel $(SPAN) --attr $(ATTRS)
116+
112117
.PHONY: gen-mocks
113118
gen-mocks: ## Generate mocks
114119
@echo "==> Generating mocks"
@@ -128,13 +133,13 @@ build: ## Generate an atlas binary in ./bin
128133
.PHONY: build-debug
129134
build-debug: ## Generate a binary in ./bin for debugging atlascli
130135
@echo "==> Building $(ATLAS_BINARY_NAME) binary for debugging"
131-
go build -gcflags="$(DEBUG_FLAGS)" -ldflags "$(LINKER_FLAGS)" $(BUILD_FLAGS) -o $(ATLAS_DESTINATION) $(ATLAS_SOURCE_FILES)
136+
go build -gcflags="$(DEBUG_FLAGS)" -ldflags "$(LINKER_FLAGS)" $(BUILD_FLAGS) -cover -o $(ATLAS_DESTINATION) $(ATLAS_SOURCE_FILES)
132137

133138
.PHONY: e2e-test
134-
e2e-test: build ## Run E2E tests
139+
e2e-test: build-debug ## Run E2E tests
135140
# the target assumes the MCLI_* environment variables are exported
136141
@echo "==> Running E2E tests..."
137-
$(TEST_CMD) -v -p 1 -parallel $(E2E_PARALLEL) -timeout $(E2E_TIMEOUT) -tags="$(E2E_TAGS)" ./test/e2e... $(E2E_EXTRA_ARGS)
142+
GOCOVERDIR=$(GOCOVERDIR) $(TEST_CMD) -v -p 1 -parallel $(E2E_PARALLEL) -v -timeout $(E2E_TIMEOUT) -tags="$(E2E_TAGS)" ./test/e2e... $(E2E_EXTRA_ARGS)
138143

139144
.PHONY: fuzz-normalizer-test
140145
fuzz-normalizer-test: ## Run fuzz test
@@ -144,7 +149,7 @@ fuzz-normalizer-test: ## Run fuzz test
144149
.PHONY: unit-test
145150
unit-test: ## Run unit-tests
146151
@echo "==> Running unit tests..."
147-
$(TEST_CMD) --tags="$(UNIT_TAGS)" -race -cover -count=1 -coverprofile $(COVERAGE) ./...
152+
$(TEST_CMD) --tags="$(UNIT_TAGS)" -race -cover -coverprofile $(COVERAGE) -count=1 ./...
148153

149154
.PHONY: install
150155
install: ## Install a binary in $GOPATH/bin

build/ci/evergreen.yml

Lines changed: 153 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,94 @@ functions:
145145
env:
146146
<<: *go_env
147147
MCLI_SKIP_UPDATE_CHECK: "yes"
148+
DO_NOT_TRACK: "1"
148149
TEST_CMD: gotestsum --junitfile e2e-tests.xml --format standard-verbose --
149150
command: make e2e-test
151+
- command: archive.targz_pack
152+
params:
153+
target: src/github.com/mongodb/mongodb-atlas-cli/coverage.tgz
154+
source_dir: src/github.com/mongodb/mongodb-atlas-cli/cov
155+
include:
156+
- '*'
157+
exclude_files:
158+
- .gitkeep
159+
- command: s3.put
160+
params:
161+
aws_key: ${aws_key}
162+
aws_secret: ${aws_secret}
163+
local_file: src/github.com/mongodb/mongodb-atlas-cli/coverage.tgz
164+
remote_file: ${project}/dist/${revision}_${created_at}/atlascli/cov/${build_variant}_${task_name}.coverage.tgz
165+
bucket: mongodb-mongocli-build
166+
permissions: public-read
167+
content_type: ${content_type|application/json}
168+
display_name: internal-bucket
169+
"merge cov":
170+
- command: subprocess.exec
171+
params:
172+
<<: *go_options
173+
binary: build/ci/merge-cov.sh
174+
- command: archive.targz_pack
175+
params:
176+
target: src/github.com/mongodb/mongodb-atlas-cli/coverage.tgz
177+
source_dir: src/github.com/mongodb/mongodb-atlas-cli/
178+
include:
179+
- 'coverage.out'
180+
- 'cov/merged/*'
181+
exclude_files:
182+
- .gitkeep
183+
- command: shell.exec
184+
params:
185+
<<: *go_options
186+
shell: bash
187+
script: |
188+
set -Eeou pipefail
189+
PERCENTAGE=$(go tool cover -func=coverage.out | grep total: | awk '{print $3}' | sed 's/%//')
190+
COUNT=$(ls -1 cov/*.tgz | wc -l)
191+
cat <<EOF > expansions.yaml
192+
percentage: $PERCENTAGE
193+
count: $COUNT
194+
EOF
195+
- command: s3.put
196+
params:
197+
aws_key: ${aws_key}
198+
aws_secret: ${aws_secret}
199+
local_file: src/github.com/mongodb/mongodb-atlas-cli/expansions.yaml
200+
remote_file: ${project}/dist/${revision}_${created_at}/atlascli/expansions.yaml
201+
bucket: mongodb-mongocli-build
202+
permissions: public-read
203+
content_type: ${content_type|application/yaml}
204+
display_name: internal-bucket expansions.yaml
205+
- command: expansions.update
206+
params:
207+
ignore_missing_file: true
208+
file: src/github.com/mongodb/mongodb-atlas-cli/expansions.yaml
209+
- command: subprocess.exec
210+
params:
211+
<<: *go_options
212+
binary: rm
213+
args:
214+
- -f
215+
- expansions.yaml
216+
- command: s3.put
217+
params:
218+
aws_key: ${aws_key}
219+
aws_secret: ${aws_secret}
220+
local_file: src/github.com/mongodb/mongodb-atlas-cli/coverage.tgz
221+
remote_file: ${project}/dist/${revision}_${created_at}/atlascli/cov/e2e.coverage.tgz
222+
bucket: mongodb-mongocli-build
223+
permissions: public-read
224+
content_type: ${content_type|application/json}
225+
display_name: internal-bucket e2e.coverage.tgz
226+
- command: s3.put
227+
params:
228+
aws_key: ${aws_key}
229+
aws_secret: ${aws_secret}
230+
local_file: src/github.com/mongodb/mongodb-atlas-cli/coverage.out
231+
remote_file: ${project}/dist/${revision}_${created_at}/atlascli/cov/e2e.coverage.out
232+
bucket: mongodb-mongocli-build
233+
permissions: public-read
234+
content_type: ${content_type|application/json}
235+
display_name: internal-bucket e2e.coverage.out
150236
"install gotestsum":
151237
- command: shell.exec
152238
type: setup
@@ -309,7 +395,7 @@ functions:
309395
bucket: mongodb-mongocli-build
310396
permissions: public-read
311397
content_type: ${content_type|application/octet-stream}
312-
display_name: internal-bucket
398+
display_name: internal-bucket terraform.tfstate
313399
- command: shell.exec
314400
params:
315401
<<: *go_options
@@ -426,6 +512,26 @@ functions:
426512
args:
427513
- -f
428514
- expansions.yaml
515+
"otel":
516+
- command: subprocess.exec
517+
params:
518+
<<: *go_options
519+
include_expansions_in_env:
520+
- go_base_path
521+
- go_proxy
522+
- workdir
523+
- project_id
524+
- project_identifier
525+
- otel_trace_id
526+
- otel_parent_id
527+
- otel_collector_endpoint
528+
env:
529+
<<: *go_env
530+
SPAN: ${span}
531+
ATTRS: ${attr}
532+
binary: make
533+
args:
534+
- otel
429535
tasks:
430536
- name: compile
431537
tags: ["code_health"]
@@ -1601,6 +1707,27 @@ tasks:
16011707
user: atlascli
16021708
identity_file: ${home}/.ssh/id_rsa
16031709
cmd: "powershell -ExecutionPolicy Bypass -File C:\\Users\\atlascli\\win_test.ps1 -goproxy ${go_proxy} -revision ${github_commit}"
1710+
- name: coverage
1711+
tags: ["coverage"]
1712+
depends_on:
1713+
- name: ".e2e"
1714+
variant: "* !.cron"
1715+
status: '*'
1716+
commands:
1717+
- command: shell.exec
1718+
params:
1719+
<<: *go_options
1720+
env:
1721+
<<: *go_env
1722+
AWS_ACCESS_KEY_ID: ${aws_key}
1723+
AWS_SECRET_ACCESS_KEY: ${aws_secret}
1724+
script: |
1725+
aws s3 sync s3://mongodb-mongocli-build/${project}/dist/${revision}_${created_at}/atlascli/cov/ ./cov/
1726+
- func: "merge cov"
1727+
- func: "otel"
1728+
vars:
1729+
span: "coverage"
1730+
attr: "total=${percentage},count=${count}"
16041731
task_groups:
16051732
- name: atlas_deployments_windows_group
16061733
setup_task:
@@ -1734,6 +1861,7 @@ buildvariants:
17341861
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
17351862
tags:
17361863
- cleanup
1864+
- cron
17371865
run_on:
17381866
- rhel80-small
17391867
expansions:
@@ -1766,6 +1894,7 @@ buildvariants:
17661894
- ubuntu2404-small
17671895
tags:
17681896
- localdev
1897+
- cron
17691898
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
17701899
expansions:
17711900
<<: *go_linux_version
@@ -1777,6 +1906,7 @@ buildvariants:
17771906
- debian11-small
17781907
tags:
17791908
- localdev
1909+
- cron
17801910
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
17811911
expansions:
17821912
<<: *go_linux_version
@@ -1788,6 +1918,7 @@ buildvariants:
17881918
- debian12-small
17891919
tags:
17901920
- localdev
1921+
- cron
17911922
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
17921923
expansions:
17931924
<<: *go_linux_version
@@ -1799,6 +1930,7 @@ buildvariants:
17991930
- amazon2023-latest-small
18001931
tags:
18011932
- localdev
1933+
- cron
18021934
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
18031935
expansions:
18041936
<<: *go_linux_version
@@ -1809,6 +1941,7 @@ buildvariants:
18091941
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
18101942
tags:
18111943
- localdev
1944+
- cron
18121945
run_on:
18131946
- rhel90-small
18141947
expansions:
@@ -1836,6 +1969,7 @@ buildvariants:
18361969
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
18371970
tags:
18381971
- localdev
1972+
- cron
18391973
run_on:
18401974
- rhel90-small
18411975
expansions:
@@ -1847,6 +1981,7 @@ buildvariants:
18471981
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
18481982
tags:
18491983
- localdev
1984+
- cron
18501985
run_on:
18511986
- rhel80-small
18521987
expansions:
@@ -1858,6 +1993,7 @@ buildvariants:
18581993
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
18591994
tags:
18601995
- localdev
1996+
- cron
18611997
run_on:
18621998
- macos-14-arm64-docker
18631999
expansions:
@@ -1869,6 +2005,7 @@ buildvariants:
18692005
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
18702006
tags:
18712007
- localdev
2008+
- cron
18722009
run_on:
18732010
- macos-13-arm64-docker
18742011
expansions:
@@ -1880,21 +2017,30 @@ buildvariants:
18802017
allowed_requesters: ["patch", "ad_hoc", "github_pr"]
18812018
tags:
18822019
- packer
2020+
- cron
18832021
run_on:
18842022
- rhel80-small
18852023
expansions:
18862024
<<: *go_linux_version
18872025
tasks:
18882026
- name: ".packer .windows"
2027+
- name: coverage
2028+
display_name: "Coverage"
2029+
run_on:
2030+
- rhel80-small
2031+
expansions:
2032+
<<: *go_linux_version
2033+
tasks:
2034+
- name: ".coverage"
18892035
patch_aliases:
18902036
- alias: "localdev"
1891-
variant_tags: ["localdev"]
2037+
variant_tags: ["localdev cron"]
18922038
task: ".*"
18932039
- alias: "packer"
1894-
variant_tags: ["packer"]
2040+
variant_tags: ["packer cron"]
18952041
task: ".*"
18962042
- alias: "cleanup"
1897-
variant_tags: ["cleanup"]
2043+
variant_tags: ["cleanup cron"]
18982044
task: ".*"
18992045
github_pr_aliases:
19002046
- variant: "code_health"
@@ -1907,3 +2053,6 @@ git_tag_aliases:
19072053
- git_tag: "atlascli/v*"
19082054
variant: "^release_atlascli"
19092055
task: ".*"
2056+
github_checks_aliases:
2057+
- variant: ".*"
2058+
task: ".*"

build/ci/library_owners.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,10 @@
5353
"sigs.k8s.io/kind": "atlas_kubernetes_team",
5454
"golang.org/x/exp": "atlas_kubernetes_team",
5555
"github.com/denisbrodbeck/machineid": "apix-2",
56-
"github.com/shirou/gopsutil/v4": "apix-2"
56+
"github.com/shirou/gopsutil/v4": "apix-2",
57+
"go.opentelemetry.io/otel": "apix-2",
58+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc": "apix-2",
59+
"go.opentelemetry.io/otel/sdk": "apix-2",
60+
"go.opentelemetry.io/otel/trace": "apix-2",
61+
"google.golang.org/grpc": "apix-2"
5762
}

build/ci/merge-cov.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 MongoDB Inc
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
dirs=""
20+
for f in cov/*.tgz; do
21+
dir="${f/.coverage.tgz/}"
22+
dirs="$dirs,$dir"
23+
mkdir -p "$dir"
24+
tar -xzvf "$f" -C "$dir"
25+
done
26+
dirs=${dirs:1}
27+
mkdir -p cov/merged
28+
go tool covdata merge -i "$dirs" -o cov/merged
29+
go tool covdata textfmt -i cov/merged -o coverage.out

cov/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)