diff options
| author | Fredrik Foss-Indrehus <fredrikfoss@fr.urbanpets.no> | 2025-05-24 21:06:53 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-24 21:06:53 +0200 |
| commit | 8024d64e1330b86044fed4c8494ef3dcd483a67c (patch) | |
| tree | de575420b901ac5dd44221c90ac51b4e75bea370 /tests | |
| parent | docs: rework Installation & Setup sections, and other minor adjustments (#1951) (diff) | |
| download | mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.gz mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.bz2 mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.lz mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.xz mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.tar.zst mason-8024d64e1330b86044fed4c8494ef3dcd483a67c.zip | |
fix(fetch): add busybox wget support (#1829)
Co-authored-by: William Boman <william@redwill.se>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-core/fetch_spec.lua | 63 |
1 files changed, 50 insertions, 13 deletions
diff --git a/tests/mason-core/fetch_spec.lua b/tests/mason-core/fetch_spec.lua index 98697563..667967b0 100644 --- a/tests/mason-core/fetch_spec.lua +++ b/tests/mason-core/fetch_spec.lua @@ -30,18 +30,21 @@ describe("fetch", function() assert.spy(spawn.curl).was_called(1) assert.spy(spawn.wget).was_called_with { { - ("--header=User-Agent: mason.nvim %s (+https://github.com/mason-org/mason.nvim)"):format( - version.VERSION - ), - "--header=X-Custom-Header: here", + { + "--header", + ("User-Agent: mason.nvim %s (+https://github.com/mason-org/mason.nvim)"):format(version.VERSION), + }, + { + "--header", + "X-Custom-Header: here", + }, }, - "-nv", "-o", "/dev/null", "-O", "-", - "--timeout=30", - "--method=GET", + "-T", + 30, vim.NIL, -- body-data "https://api.github.com", } @@ -86,17 +89,17 @@ describe("fetch", function() assert.spy(spawn.wget).was_called_with { { - ("--header=User-Agent: mason.nvim %s (+https://github.com/mason-org/mason.nvim)"):format( - version.VERSION - ), + { + "--header", + ("User-Agent: mason.nvim %s (+https://github.com/mason-org/mason.nvim)"):format(version.VERSION), + }, }, - "-nv", "-o", "/dev/null", "-O", "/test.json", - "--timeout=30", - "--method=GET", + "-T", + 30, vim.NIL, -- body-data "https://api.github.com/data", } @@ -118,3 +121,37 @@ describe("fetch", function() }) end) end) + +describe("fetch :: wget", function() + it("should reject non-supported HTTP methods", function() + stub(spawn, "wget") + stub(spawn, "curl") + spawn.wget.returns(Result.failure "wget failure") + spawn.curl.returns(Result.failure "curl failure") + local PATCH_ERR = assert.has_error(function() + fetch("https://api.github.com/data", { method = "PATCH" }):get_or_throw() + end) + local DELETE_ERR = assert.has_error(function() + fetch("https://api.github.com/data", { method = "DELETE" }):get_or_throw() + end) + local PUT_ERR = assert.has_error(function() + fetch("https://api.github.com/data", { method = "PUT" }):get_or_throw() + end) + + assert.equals("fetch: wget doesn't support HTTP method PATCH", PATCH_ERR) + assert.equals("fetch: wget doesn't support HTTP method DELETE", DELETE_ERR) + assert.equals("fetch: wget doesn't support HTTP method PUT", PUT_ERR) + end) + + it("should reject requests with opts.data if not opts.method is not POST", function() + stub(spawn, "wget") + stub(spawn, "curl") + spawn.wget.returns(Result.failure "wget failure") + spawn.curl.returns(Result.failure "curl failure") + local err = assert.has_error(function() + fetch("https://api.github.com/data", { data = "data" }):get_or_throw() + end) + + assert.equals("fetch: data provided but method is not POST (was GET)", err) + end) +end) |
