Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·128 lines (117 loc) · 4.05 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·128 lines (117 loc) · 4.05 KB
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
#!/usr/bin/env bash
set -euo pipefail
# message: Prints a message to the console with a timestamp and prefix.
message() {
local msg="$1"
printf "\n> %s - %s\n" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$msg"
}
# run: Runs the tool and fails early if it fails.
run() {
local cmd="$1"
message "Running: $cmd"
if ! eval "$cmd"; then
message "Command failed: $cmd"
exit 1
fi
message "Command ran successfully: $cmd"
}
contrib=""
unset INTEGRATION
unset DD_APPSEC_ENABLED
unset __DD_TRACE_SQL_TEST
# Build tags support (e.g., BUILD_TAGS=deadlock or BUILD_TAGS=debug,deadlock)
# Use an array to avoid shellcheck warnings about word splitting with empty strings
TAGS_FLAG=()
if [[ -n "${BUILD_TAGS:-}" ]]; then
TAGS_FLAG=("-tags=${BUILD_TAGS}")
message "Using build tags: ${BUILD_TAGS}"
fi
if [[ "$(uname -s)" = 'Darwin' && "$(uname -m)" = 'arm64' ]]; then
# Needed to run integration tests on Apple Silicon
export DOCKER_DEFAULT_PLATFORM=linux/amd64
fi
while [[ $# -gt 0 ]]; do
case $1 in
-a | --appsec)
export DD_APPSEC_ENABLED=true
shift
;;
-i | --integration)
export INTEGRATION=true
export __DD_TRACE_SQL_TEST=true
shift
;;
-c | --contrib)
contrib=true
shift
;;
--all)
contrib=true
export DD_APPSEC_ENABLED=true
export DD_TEST_APPS_ENABLED=true
export INTEGRATION=true
export __DD_TRACE_SQL_TEST=true
shift
;;
-h | --help)
echo "test.sh - Run the tests for dd-trace-go"
echo " this script requires gotestsum, goimports, docker and docker-compose."
echo " -a | --appsec - Test with appsec enabled"
echo " -i | --integration - Run integration tests. This requires docker and docker-compose. Resource usage is significant when combined with --contrib"
echo " -c | --contrib - Run contrib tests"
echo " --all - Synonym for -l -a -i -c"
echo " -t | --tools - Install gotestsum and goimports"
echo " -h | --help - Print this help message"
echo ""
echo "Environment Variables:"
echo " BUILD_TAGS - Comma-separated Go build tags (e.g., BUILD_TAGS=deadlock or BUILD_TAGS=debug,deadlock)"
exit 0
;;
*)
echo "Ignoring unknown argument $1"
shift
;;
esac
done
if [[ "${INTEGRATION:-}" != "" ]]; then
## Make sure we shut down the docker containers on exit.
function finish {
message "Cleaning up..."
docker compose down
}
trap finish EXIT
if [[ "$contrib" != "" ]]; then
## Start these now and block until their healthchecks pass, so they'll be
## ready by the time we run integration tests.
docker compose up -d --wait --wait-timeout 600
else
## If we're not testing contrib, we only need the trace agent.
docker compose up -d --wait --wait-timeout 600 datadog-agent
fi
fi
## CORE
message "Testing core..."
mapfile -t pkg_names < <(go list "${TAGS_FLAG[@]}" ./...)
nice -n20 gotestsum --junitfile ./gotestsum-report.xml -- "${TAGS_FLAG[@]}" -race -v -coverprofile=core_coverage.txt -covermode=atomic "${pkg_names[@]}" && true
if [[ "$contrib" != "" ]]; then
## CONTRIB
message "Testing contrib..."
find . -mindepth 2 -type f -name go.mod | while read -r go_mod_path; do
dir=$(dirname "$go_mod_path")
[ "$dir" = "./tools/v2fix/_stage" ] && continue
[ "$dir" = "./scripts/autoreleasetagger/testdata/root" ] && continue
[ "$dir" = "./scripts/autoreleasetagger/testdata/root/moduleA" ] && continue
[ "$dir" = "./scripts/autoreleasetagger/testdata/root/moduleB" ] && continue
cd "$dir"
message "Testing $dir"
mapfile -t pkgs < <(go list "${TAGS_FLAG[@]}" ./... | grep -v -e google.golang.org/api)
if [[ ${#pkgs[@]} -eq 0 ]]; then
cd - > /dev/null
continue
fi
pkg_id="${pkgs[0]#github.com/DataDog/dd-trace-go/v2}"
pkg_id="${pkg_id//\//_}"
nice -n20 gotestsum --junitfile "./gotestsum-report.$pkg_id.xml" -- "${TAGS_FLAG[@]}" -race -v -coverprofile="contrib_coverage.$pkg_id.txt" -covermode=atomic "${pkgs[@]}"
cd - > /dev/null
done
fi