var assert = require('assert');
var crypto = require('crypto');
var fs = require('fs');
var TileJSON = require('..');

function md5(str) {
  return crypto.createHash('md5').update(str).digest('hex');
}

try { fs.unlink(__dirname + '/fixtures/grid.tilejson.cache'); } catch (err) {}


exports['test loading interactivity'] = function(beforeExit) {
    var completed = {};

    var source = new TileJSON('tilejson://' + __dirname + '/fixtures/grid.tilejson', function(err) {
        completed.load = true;
        if (err) throw err;

        source.getGrid(6, 29, 30, function(err, data, headers) {
            completed.tile_6_29_30_1 = true;
            assert.isNull(err);
            assert.equal('4b06ccac5efba3c4eaee3b29a1389fa0', md5(JSON.stringify(data)));
            assert.ok(headers['Content-Type']);
            assert.ok(headers['Last-Modified']);
            assert.ok(headers['ETag']);

            // Request the same again to test caching.
            source.getGrid(6, 29, 30, function(err, data, headers) {
                completed.tile_6_29_30_2 = true;
                assert.isNull(err);
                assert.equal('4b06ccac5efba3c4eaee3b29a1389fa0', md5(JSON.stringify(data)));
                assert.ok(headers['Content-Type']);
                assert.ok(headers['Last-Modified']);
                assert.ok(headers['ETag']);
                source._close();
            });
        });
    });

    beforeExit(function() {
        assert.deepEqual(completed, {
            load: true,
            tile_6_29_30_1: true,
            tile_6_29_30_2: true
        });
    });
};

@@ -699,39 +699,39 @@
 l('4
-b06ccac5efba3c4eaee3b29a1389fa0
+f8790dc72e204132531f1e12dea20a1
 ', m
@@ -775,32 +775,24 @@
   assert.ok(
-headers%5B
 'Content-Typ
@@ -785,33 +785,43 @@
 k('Content-Type'
-%5D
+ in headers
 );%0A            a
@@ -825,32 +825,24 @@
   assert.ok(
-headers%5B
 'Last-Modifi
@@ -836,33 +836,43 @@
 ('Last-Modified'
-%5D
+ in headers
 );%0A            a
@@ -880,31 +880,33 @@
 sert.ok(
-headers%5B'ETag'%5D
+'ETag' in headers
 );%0A%0A    
@@ -1145,39 +1145,39 @@
 l('4
-b06ccac5efba3c4eaee3b29a1389fa0
+f8790dc72e204132531f1e12dea20a1
 ', m
@@ -1229,24 +1229,16 @@
 sert.ok(
-headers%5B
 'Content
@@ -1243,17 +1243,27 @@
 nt-Type'
-%5D
+ in headers
 );%0A     
@@ -1283,24 +1283,16 @@
 sert.ok(
-headers%5B
 'Last-Mo
@@ -1298,17 +1298,27 @@
 odified'
-%5D
+ in headers
 );%0A     
@@ -1342,23 +1342,25 @@
 .ok(
-headers%5B'ETag'%5D
+'ETag' in headers
 );%0A 

Update test assertions.