-
Notifications
You must be signed in to change notification settings - Fork 89
/
verify.js
51 lines (40 loc) · 1.63 KB
/
verify.js
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
"use strict";
var util = require("util");
var async = require("async"),
request = require("request"),
merc = new (require("sphericalmercator"))();
var STAMEN = [-122.41934,37.7648797];
var endpoint = process.argv[2];
var config = require("./tessera.json");
var tests = [];
Object.keys(config).forEach(function(prefix) {
for (var i=0; i <= 20; i++) { tests.push({"zoom":i, "prefix":prefix}); }
});
console.log("Endpoint: " + endpoint);
console.log("Tests: " + tests.length);
var funs = tests.map(function(test) {
var px = merc.px(STAMEN,test.zoom),
tile = {
x: Math.floor(px[0] / 256),
y: Math.floor(px[1] / 256),
z: test.zoom
},
uri = util.format("%s%s/%d/%d/%d.png", endpoint, test.prefix, tile.z, tile.x, tile.y);
return [uri, function(callback) {
return request(uri, function (error, response, body) {
if (response.statusCode !== 200) {
console.log(uri + " is " + response.statusCode);
}
return callback(null, response.statusCode, body);
});
}];
}).reduce(function(obj, v) {
obj[v[0]] = v[1];
return obj;
}, {});
async.parallel(funs, function(err, results) {
console.log("2xx: " + Object.keys(results).filter(function(k) { return results[k][0] >= 200 && results[k][0] < 300 }).length);
console.log("3xx: " + Object.keys(results).filter(function(k) { return results[k][0] >= 300 && results[k][0] < 400 }).length);
console.log("4xx: " + Object.keys(results).filter(function(k) { return results[k][0] >= 400 && results[k][0] < 500 }).length);
console.log("5xx: " + Object.keys(results).filter(function(k) { return results[k][0] >= 500 }).length);
});