Skip to content

Commit 0ec6da1

Browse files
committed
allow multi location
1 parent e936e50 commit 0ec6da1

2 files changed

Lines changed: 49 additions & 10 deletions

File tree

src/services/testConfigBuilder.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ export class TestConfigBuilder {
2424
}
2525

2626
public withLocations(locations: string | string[]): TestConfigBuilder {
27+
// Convert to array if string
2728
const locationsArray = Array.isArray(locations) ? locations : [locations];
28-
this.config.locations = locationsArray.map(loc => ({ magic: loc }));
29+
30+
// Split comma-separated locations and flatten
31+
const expandedLocations = locationsArray.flatMap(loc =>
32+
loc.split(',').map(l => l.trim()).filter(l => l.length > 0)
33+
);
34+
35+
this.config.locations = expandedLocations.map(loc => ({ magic: loc }));
2936
return this;
3037
}
3138

src/views/testRunnerViewProvider.ts

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,13 @@ export class TestRunnerViewProvider implements vscode.WebviewViewProvider {
776776
document.getElementById('testType').value = config.type;
777777
document.getElementById('target').value = config.target;
778778
779-
// Location: extract magic field from locations array
779+
// Location: extract magic fields from locations array and join with commas
780780
if (Array.isArray(config.locations) && config.locations.length > 0) {
781-
const location = config.locations[0].magic || 'World';
782-
document.getElementById('location').value = location;
781+
const locations = config.locations
782+
.map(loc => loc.magic)
783+
.filter(magic => magic)
784+
.join(', ');
785+
document.getElementById('location').value = locations || 'World';
783786
}
784787
785788
document.getElementById('limit').value = config.limit || 3;
@@ -1133,6 +1136,7 @@ export class TestRunnerViewProvider implements vscode.WebviewViewProvider {
11331136
// Collect test-specific options
11341137
function collectTestOptions(testType) {
11351138
const ipVersion = parseInt(document.getElementById('ipVersion').value);
1139+
const target = document.getElementById('target').value.trim();
11361140
11371141
// Helper to check if a string is an IP address (IPv4 or IPv6)
11381142
function isIpAddress(str) {
@@ -1143,15 +1147,35 @@ export class TestRunnerViewProvider implements vscode.WebviewViewProvider {
11431147
return ipv4Pattern.test(str) || ipv6Pattern.test(str);
11441148
}
11451149
1150+
// Extract hostname/IP from target (remove protocol, path, etc.)
1151+
function extractHostname(targetStr) {
1152+
// Remove protocol if present
1153+
let hostname = targetStr.replace(/^https?:\\/\\//, '');
1154+
// Remove path/query/fragment
1155+
hostname = hostname.split('/')[0].split('?')[0].split('#')[0];
1156+
// Remove port
1157+
hostname = hostname.split(':')[0];
1158+
return hostname;
1159+
}
1160+
1161+
const hostname = extractHostname(target);
1162+
const targetIsIp = isIpAddress(hostname);
1163+
11461164
const options = {};
11471165
11481166
switch (testType) {
11491167
case 'ping':
1150-
options.ipVersion = ipVersion;
1168+
// Only include ipVersion if target is a domain (not an IP)
1169+
if (!targetIsIp) {
1170+
options.ipVersion = ipVersion;
1171+
}
11511172
options.protocol = document.getElementById('pingProtocol').value;
11521173
break;
11531174
case 'http':
1154-
options.ipVersion = ipVersion;
1175+
// Only include ipVersion if target is a domain (not an IP)
1176+
if (!targetIsIp) {
1177+
options.ipVersion = ipVersion;
1178+
}
11551179
options.method = document.getElementById('httpMethod').value;
11561180
options.protocol = document.getElementById('httpProtocol').value;
11571181
options.port = parseInt(document.getElementById('httpPort').value);
@@ -1168,17 +1192,25 @@ export class TestRunnerViewProvider implements vscode.WebviewViewProvider {
11681192
options.ipVersion = ipVersion;
11691193
}
11701194
} else {
1171-
// No resolver specified - ipVersion is allowed
1172-
options.ipVersion = ipVersion;
1195+
// No resolver specified - check target
1196+
if (!targetIsIp) {
1197+
options.ipVersion = ipVersion;
1198+
}
11731199
}
11741200
break;
11751201
}
11761202
case 'traceroute':
1177-
options.ipVersion = ipVersion;
1203+
// Only include ipVersion if target is a domain (not an IP)
1204+
if (!targetIsIp) {
1205+
options.ipVersion = ipVersion;
1206+
}
11781207
options.protocol = document.getElementById('tracerouteProtocol').value;
11791208
break;
11801209
case 'mtr':
1181-
options.ipVersion = ipVersion;
1210+
// Only include ipVersion if target is a domain (not an IP)
1211+
if (!targetIsIp) {
1212+
options.ipVersion = ipVersion;
1213+
}
11821214
options.protocol = document.getElementById('mtrProtocol').value;
11831215
break;
11841216
}

0 commit comments

Comments
 (0)