@@ -30,18 +30,21 @@ describe("fetch", function()
3030 assert .spy (spawn .curl ).was_called (1 )
3131 assert .spy (spawn .wget ).was_called_with {
3232 {
33- (" --header=User-Agent: mason.nvim %s (+https://github.com/mason-org/mason.nvim)" ):format (
34- version .VERSION
35- ),
36- " --header=X-Custom-Header: here" ,
33+ {
34+ " --header" ,
35+ (" User-Agent: mason.nvim %s (+https://github.com/mason-org/mason.nvim)" ):format (version .VERSION ),
36+ },
37+ {
38+ " --header" ,
39+ " X-Custom-Header: here" ,
40+ },
3741 },
38- " -nv" ,
3942 " -o" ,
4043 " /dev/null" ,
4144 " -O" ,
4245 " -" ,
43- " --timeout=30 " ,
44- " --method=GET " ,
46+ " -T " ,
47+ 30 ,
4548 vim .NIL , -- body-data
4649 " https://api.github.com" ,
4750 }
@@ -86,17 +89,17 @@ describe("fetch", function()
8689
8790 assert .spy (spawn .wget ).was_called_with {
8891 {
89- (" --header=User-Agent: mason.nvim %s (+https://github.com/mason-org/mason.nvim)" ):format (
90- version .VERSION
91- ),
92+ {
93+ " --header" ,
94+ (" User-Agent: mason.nvim %s (+https://github.com/mason-org/mason.nvim)" ):format (version .VERSION ),
95+ },
9296 },
93- " -nv" ,
9497 " -o" ,
9598 " /dev/null" ,
9699 " -O" ,
97100 " /test.json" ,
98- " --timeout=30 " ,
99- " --method=GET " ,
101+ " -T " ,
102+ 30 ,
100103 vim .NIL , -- body-data
101104 " https://api.github.com/data" ,
102105 }
@@ -118,3 +121,37 @@ describe("fetch", function()
118121 })
119122 end )
120123end )
124+
125+ describe (" fetch :: wget" , function ()
126+ it (" should reject non-supported HTTP methods" , function ()
127+ stub (spawn , " wget" )
128+ stub (spawn , " curl" )
129+ spawn .wget .returns (Result .failure " wget failure" )
130+ spawn .curl .returns (Result .failure " curl failure" )
131+ local PATCH_ERR = assert .has_error (function ()
132+ fetch (" https://api.github.com/data" , { method = " PATCH" }):get_or_throw ()
133+ end )
134+ local DELETE_ERR = assert .has_error (function ()
135+ fetch (" https://api.github.com/data" , { method = " DELETE" }):get_or_throw ()
136+ end )
137+ local PUT_ERR = assert .has_error (function ()
138+ fetch (" https://api.github.com/data" , { method = " PUT" }):get_or_throw ()
139+ end )
140+
141+ assert .equals (" fetch: wget doesn't support HTTP method PATCH" , PATCH_ERR )
142+ assert .equals (" fetch: wget doesn't support HTTP method DELETE" , DELETE_ERR )
143+ assert .equals (" fetch: wget doesn't support HTTP method PUT" , PUT_ERR )
144+ end )
145+
146+ it (" should reject requests with opts.data if not opts.method is not POST" , function ()
147+ stub (spawn , " wget" )
148+ stub (spawn , " curl" )
149+ spawn .wget .returns (Result .failure " wget failure" )
150+ spawn .curl .returns (Result .failure " curl failure" )
151+ local err = assert .has_error (function ()
152+ fetch (" https://api.github.com/data" , { data = " data" }):get_or_throw ()
153+ end )
154+
155+ assert .equals (" fetch: data provided but method is not POST (was GET)" , err )
156+ end )
157+ end )
0 commit comments