Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·173 lines (147 loc) · 3.88 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·173 lines (147 loc) · 3.88 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# staticSend Test Runner Script
# This script provides a simple way to run different types of tests
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to run unit tests
run_unit_tests() {
print_status "Running unit tests..."
if go test ./pkg/... -v -cover; then
print_success "Unit tests passed!"
return 0
else
print_error "Unit tests failed!"
return 1
fi
}
# Function to run integration tests
run_integration_tests() {
print_status "Running integration tests..."
if go test -v ./integration_test.go; then
print_success "Integration tests passed!"
return 0
else
print_error "Integration tests failed!"
return 1
fi
}
# Function to run all tests
run_all_tests() {
print_status "Running all tests..."
unit_result=0
integration_result=0
# Run unit tests
if ! run_unit_tests; then
unit_result=1
fi
echo ""
# Run integration tests
if ! run_integration_tests; then
integration_result=1
fi
echo ""
# Summary
if [ $unit_result -eq 0 ] && [ $integration_result -eq 0 ]; then
print_success "All tests passed! ✅"
return 0
else
if [ $unit_result -ne 0 ]; then
print_error "Unit tests failed ❌"
fi
if [ $integration_result -ne 0 ]; then
print_error "Integration tests failed ❌"
fi
return 1
fi
}
# Function to run tests with coverage
run_coverage() {
print_status "Running tests with coverage report..."
# Create coverage directory if it doesn't exist
mkdir -p coverage
# Run unit tests with coverage
if go test ./pkg/... -coverprofile=coverage/coverage.out; then
# Generate HTML coverage report
go tool cover -html=coverage/coverage.out -o coverage/coverage.html
print_success "Coverage report generated: coverage/coverage.html"
# Show coverage summary
print_status "Coverage summary:"
go tool cover -func=coverage/coverage.out | tail -1
return 0
else
print_error "Coverage tests failed!"
return 1
fi
}
# Function to show help
show_help() {
echo "staticSend Test Runner"
echo ""
echo "Usage: $0 [COMMAND]"
echo ""
echo "Commands:"
echo " unit Run unit tests only"
echo " integration Run integration tests only"
echo " all Run all tests (default)"
echo " coverage Run tests with coverage report"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Run all tests"
echo " $0 unit # Run unit tests only"
echo " $0 integration # Run integration tests only"
echo " $0 coverage # Run with coverage report"
}
# Main script logic
main() {
case "${1:-all}" in
"unit")
run_unit_tests
;;
"integration")
run_integration_tests
;;
"all")
run_all_tests
;;
"coverage")
run_coverage
;;
"help"|"-h"|"--help")
show_help
;;
*)
print_error "Unknown command: $1"
echo ""
show_help
exit 1
;;
esac
}
# Check if Go is installed
if ! command -v go &> /dev/null; then
print_error "Go is not installed or not in PATH"
exit 1
fi
# Change to script directory
cd "$(dirname "$0")/.."
# Run main function with all arguments
main "$@"