MCPcopy
hub / github.com/request/request / runTest

Function runTest

tests/test-multipart.js:9–106  ·  view source on GitHub ↗
(t, a)

Source from the content-addressed store, hash-verified

7var tape = require('tape')
8
9function runTest (t, a) {
10 var remoteFile = path.join(__dirname, 'googledoodle.jpg')
11 var localFile = path.join(__dirname, 'unicycle.jpg')
12 var multipartData = []
13
14 var server = http.createServer(function (req, res) {
15 if (req.url === '/file') {
16 res.writeHead(200, {'content-type': 'image/jpg'})
17 res.end(fs.readFileSync(remoteFile), 'binary')
18 return
19 }
20
21 if (a.header) {
22 if (a.header.indexOf('mixed') !== -1) {
23 t.ok(req.headers['content-type'].match(/^multipart\/mixed; boundary=[^\s;]+$/))
24 } else {
25 t.ok(req.headers['content-type']
26 .match(/^multipart\/related; boundary=XXX; type=text\/xml; start="<root>"$/))
27 }
28 } else {
29 t.ok(req.headers['content-type'].match(/^multipart\/related; boundary=[^\s;]+$/))
30 }
31
32 // temp workaround
33 var data = ''
34 req.setEncoding('utf8')
35
36 req.on('data', function (d) {
37 data += d
38 })
39
40 req.on('end', function () {
41 // check for the fields traces
42
43 // my_field
44 t.ok(data.indexOf('name: my_field') !== -1)
45 t.ok(data.indexOf(multipartData[0].body) !== -1)
46
47 // my_number
48 t.ok(data.indexOf('name: my_number') !== -1)
49 t.ok(data.indexOf(multipartData[1].body) !== -1)
50
51 // my_buffer
52 t.ok(data.indexOf('name: my_buffer') !== -1)
53 t.ok(data.indexOf(multipartData[2].body) !== -1)
54
55 // my_file
56 t.ok(data.indexOf('name: my_file') !== -1)
57 // check for unicycle.jpg traces
58 t.ok(data.indexOf('2005:06:21 01:44:12') !== -1)
59
60 // remote_file
61 t.ok(data.indexOf('name: remote_file') !== -1)
62 // check for http://localhost:nnnn/file traces
63 t.ok(data.indexOf('Photoshop ICC') !== -1)
64
65 if (a.header && a.header.indexOf('boundary=XXX') !== -1) {
66 t.ok(data.indexOf('--XXX') !== -1)

Callers 1

test-multipart.jsFile · 0.70

Calls 1

requestFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…