-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_config.sh
More file actions
executable file
Β·216 lines (183 loc) Β· 5.63 KB
/
test_config.sh
File metadata and controls
executable file
Β·216 lines (183 loc) Β· 5.63 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
# Integration test for otlp-mcp configuration file feature
# Tests various configuration scenarios and precedence rules
set -e # Exit on error
echo "π§ͺ Testing otlp-mcp configuration file feature"
echo "=============================================="
# Save original directory
ORIGINAL_DIR=$(pwd)
# Build the binary first
echo "π¦ Building otlp-mcp..."
go build -o otlp-mcp ./cmd/otlp-mcp || exit 1
# Create a temporary directory for tests
TEST_DIR=$(mktemp -d)
echo "π Using test directory: $TEST_DIR"
# Copy binary to test directory
cp otlp-mcp "$TEST_DIR/"
# Change to test directory for all tests
cd "$TEST_DIR"
# Cleanup function
cleanup() {
cd "$ORIGINAL_DIR"
rm -rf "$TEST_DIR"
}
# Set trap to cleanup on exit
trap cleanup EXIT
# Helper function to extract port from verbose output
extract_port() {
echo "$1" | grep "OTLP bind:" | sed 's/.*://' | tr -d ' '
}
# Helper function to extract buffer size from verbose output
extract_trace_buffer() {
echo "$1" | grep "Trace buffer:" | head -1 | sed 's/.*: //' | sed 's/ spans//' | tr -d ' '
}
# Test 1: Default configuration (no config file)
echo ""
echo "Test 1: Default configuration (no config file)"
echo "-----------------------------------------------"
OUTPUT=$(./otlp-mcp serve --verbose 2>&1 | head -20)
PORT=$(extract_port "$OUTPUT")
TRACE_BUF=$(extract_trace_buffer "$OUTPUT")
if [ "$PORT" = "0" ]; then
echo "β
Default: Using ephemeral port (0)"
else
echo "β Expected ephemeral port (0), got: $PORT"
exit 1
fi
if [ "$TRACE_BUF" = "10000" ]; then
echo "β
Default: Trace buffer is 10000"
else
echo "β Expected trace buffer 10000, got: $TRACE_BUF"
exit 1
fi
# Test 2: Project config file (.otlp-mcp.json)
echo ""
echo "Test 2: Project config file (.otlp-mcp.json)"
echo "---------------------------------------------"
# Create test project config
cat > .otlp-mcp.json <<EOF
{
"comment": "Test project config",
"otlp_port": 4317,
"trace_buffer_size": 15000
}
EOF
OUTPUT=$(./otlp-mcp serve --verbose 2>&1 | head -20)
PORT=$(extract_port "$OUTPUT")
TRACE_BUF=$(extract_trace_buffer "$OUTPUT")
if [ "$PORT" = "4317" ]; then
echo "β
Project config: Using port 4317"
else
echo "β Expected port 4317, got: $PORT"
exit 1
fi
if [ "$TRACE_BUF" = "15000" ]; then
echo "β
Project config: Trace buffer is 15000"
else
echo "β Expected trace buffer 15000, got: $TRACE_BUF"
exit 1
fi
# Test 3: CLI flag overrides config file
echo ""
echo "Test 3: CLI flag overrides config file"
echo "---------------------------------------"
OUTPUT=$(./otlp-mcp serve --otlp-port 5555 --trace-buffer-size 20000 --verbose 2>&1 | head -20)
PORT=$(extract_port "$OUTPUT")
TRACE_BUF=$(extract_trace_buffer "$OUTPUT")
if [ "$PORT" = "5555" ]; then
echo "β
CLI override: Using port 5555"
else
echo "β Expected port 5555, got: $PORT"
exit 1
fi
if [ "$TRACE_BUF" = "20000" ]; then
echo "β
CLI override: Trace buffer is 20000"
else
echo "β Expected trace buffer 20000, got: $TRACE_BUF"
exit 1
fi
# Test 4: Explicit config file via --config flag
echo ""
echo "Test 4: Explicit config file via --config flag"
echo "-----------------------------------------------"
cat > /tmp/custom-config.json <<EOF
{
"comment": "Custom test config",
"otlp_port": 9999,
"trace_buffer_size": 30000,
"log_buffer_size": 150000
}
EOF
OUTPUT=$(./otlp-mcp serve --config /tmp/custom-config.json --verbose 2>&1 | head -20)
PORT=$(extract_port "$OUTPUT")
TRACE_BUF=$(extract_trace_buffer "$OUTPUT")
if [ "$PORT" = "9999" ]; then
echo "β
Custom config: Using port 9999"
else
echo "β Expected port 9999, got: $PORT"
exit 1
fi
if [ "$TRACE_BUF" = "30000" ]; then
echo "β
Custom config: Trace buffer is 30000"
else
echo "β Expected trace buffer 30000, got: $TRACE_BUF"
exit 1
fi
# Test 5: Config file with comment field
echo ""
echo "Test 5: Config file with comment field"
echo "---------------------------------------"
cat > /tmp/comment-config.json <<EOF
{
"comment": "This is a test configuration with documentation",
"otlp_port": 7777
}
EOF
OUTPUT=$(./otlp-mcp serve --config /tmp/comment-config.json --verbose 2>&1 | head -20)
PORT=$(extract_port "$OUTPUT")
if [ "$PORT" = "7777" ]; then
echo "β
Comment field: Config loads correctly with comment"
else
echo "β Failed to load config with comment field"
exit 1
fi
# Test 6: Invalid JSON should fail gracefully
echo ""
echo "Test 6: Invalid JSON handling"
echo "------------------------------"
cat > /tmp/invalid-config.json <<EOF
{
"otlp_port": 4317
"missing_comma": true
}
EOF
OUTPUT=$(./otlp-mcp serve --config /tmp/invalid-config.json 2>&1 || true)
if echo "$OUTPUT" | grep -q "failed to parse config file"; then
echo "β
Invalid JSON: Proper error message"
else
echo "β Expected parse error for invalid JSON"
exit 1
fi
# Test 7: Nonexistent config file with --config should fail
echo ""
echo "Test 7: Nonexistent config file handling"
echo "-----------------------------------------"
OUTPUT=$(./otlp-mcp serve --config /tmp/nonexistent-config.json 2>&1 || true)
if echo "$OUTPUT" | grep -q "failed to read config file"; then
echo "β
Nonexistent file: Proper error message"
else
echo "β Expected read error for nonexistent file"
exit 1
fi
echo ""
echo "=============================================="
echo "π All configuration tests passed!"
echo ""
echo "Summary:"
echo "- Default configuration works"
echo "- Project config file is loaded correctly"
echo "- CLI flags override config files"
echo "- Custom config paths work"
echo "- Comment fields are handled"
echo "- Invalid configs fail gracefully"
echo "- Missing configs fail gracefully"