]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/test/request-gzip-content.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / npm-registry-client / test / request-gzip-content.js
diff --git a/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/test/request-gzip-content.js b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/test/request-gzip-content.js
new file mode 100644 (file)
index 0000000..5e25214
--- /dev/null
@@ -0,0 +1,61 @@
+var zlib = require('zlib')
+var test = require('tap').test
+
+var server = require('./lib/server.js')
+var common = require('./lib/common.js')
+var client = common.freshClient({
+  retry: {
+    count: 1,
+    minTimeout: 10,
+    maxTimeout: 100
+  }
+})
+
+var TEST_URL = common.registry + '/some-package-gzip/1.2.3'
+
+var pkg = {
+  _id: 'some-package-gzip@1.2.3',
+  name: 'some-package-gzip',
+  version: '1.2.3'
+}
+
+zlib.gzip(JSON.stringify(pkg), function (err, pkgGzip) {
+  test('request gzip package content', function (t) {
+    t.ifError(err, 'example package compressed')
+
+    server.expect('GET', '/some-package-gzip/1.2.3', function (req, res) {
+      res.statusCode = 200
+      res.setHeader('Content-Encoding', 'gzip')
+      res.setHeader('Content-Type', 'application/json')
+      res.end(pkgGzip)
+    })
+
+    client.get(TEST_URL, {}, function (er, data) {
+      if (er) throw er
+      t.deepEqual(data, pkg, 'some-package-gzip version 1.2.3')
+      t.end()
+    })
+  })
+
+  test('request wrong gzip package content', function (t) {
+    // will retry 3 times
+    for (var i = 0; i < 3; i++) {
+      server.expect('GET', '/some-package-gzip/1.2.3', function (req, res) {
+        res.statusCode = 200
+        res.setHeader('Content-Encoding', 'gzip')
+        res.setHeader('Content-Type', 'application/json')
+        res.end(new Buffer('wrong gzip content'))
+      })
+    }
+
+    client.get(TEST_URL, {}, function (er) {
+      t.ok(er, 'ungzip error')
+      t.end()
+    })
+  })
+
+  test('cleanup', function (t) {
+    server.close()
+    t.end()
+  })
+})