forked from request/request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-errors.js
108 lines (95 loc) · 2.17 KB
/
test-errors.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use strict'
var request = require('../index')
var tape = require('tape')
var local = 'http://localhost:0/asdf'
tape('without uri', function (t) {
t.throws(function () {
request({})
}, /^Error: options\.uri is a required argument$/)
t.end()
})
tape('invalid uri 1', function (t) {
t.throws(function () {
request({
uri: 'this-is-not-a-valid-uri'
})
}, /^Error: Invalid URI/)
t.end()
})
tape('invalid uri 2', function (t) {
t.throws(function () {
request({
uri: 'github.com/uri-is-not-valid-without-protocol'
})
}, /^Error: Invalid URI/)
t.end()
})
tape('invalid uri + NO_PROXY', function (t) {
process.env.NO_PROXY = 'google.com'
t.throws(function () {
request({
uri: 'invalid'
})
}, /^Error: Invalid URI/)
delete process.env.NO_PROXY
t.end()
})
tape('deprecated unix URL', function (t) {
t.throws(function () {
request({
uri: 'unix://path/to/socket/and/then/request/path'
})
}, /^Error: `unix:\/\/` URL scheme is no longer supported/)
t.end()
})
tape('invalid body', function (t) {
t.throws(function () {
request({
uri: local, body: {}
})
}, /^Error: Argument error, options\.body\.$/)
t.end()
})
tape('invalid multipart', function (t) {
t.throws(function () {
request({
uri: local,
multipart: 'foo'
})
}, /^Error: Argument error, options\.multipart\.$/)
t.end()
})
tape('multipart without body 1', function (t) {
t.throws(function () {
request({
uri: local,
multipart: [ {} ]
})
}, /^Error: Body attribute missing in multipart\.$/)
t.end()
})
tape('multipart without body 2', function (t) {
t.throws(function () {
request(local, {
multipart: [ {} ]
})
}, /^Error: Body attribute missing in multipart\.$/)
t.end()
})
tape('head method with a body', function (t) {
t.throws(function () {
request(local, {
method: 'HEAD',
body: 'foo'
})
}, /HTTP HEAD requests MUST NOT include a request body/)
t.end()
})
tape('head method with a body 2', function (t) {
t.throws(function () {
request.head(local, {
body: 'foo'
})
}, /HTTP HEAD requests MUST NOT include a request body/)
t.end()
})