diff options
| author | William Boman <william@redwill.se> | 2022-04-11 17:19:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-11 17:19:01 +0200 |
| commit | 88f590ce0e01767bcc8dfdc862a456efde77d4a0 (patch) | |
| tree | 2f5faaffa76b9147a873b2adc3286b6624144976 /tests/core | |
| parent | fix(verible): use correct unpacked directory name on Windows (#589) (diff) | |
| download | mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.gz mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.bz2 mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.lz mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.xz mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.tar.zst mason-88f590ce0e01767bcc8dfdc862a456efde77d4a0.zip | |
more async refactor (#587)
Diffstat (limited to 'tests/core')
| -rw-r--r-- | tests/core/fetch_spec.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/core/fetch_spec.lua b/tests/core/fetch_spec.lua new file mode 100644 index 00000000..dac7c7b8 --- /dev/null +++ b/tests/core/fetch_spec.lua @@ -0,0 +1,49 @@ +local stub = require "luassert.stub" +local fetch = require "nvim-lsp-installer.core.fetch" +local spawn = require "nvim-lsp-installer.core.spawn" +local Result = require "nvim-lsp-installer.core.result" + +describe("fetch", function() + it( + "should exhaust all candidates", + async_test(function() + stub(spawn, "wget") + stub(spawn, "curl") + spawn.wget.returns(Result.failure "wget failure") + spawn.curl.returns(Result.failure "curl failure") + + local result = fetch "https://api.github.com" + assert.is_true(result:is_failure()) + assert.spy(spawn.wget).was_called(1) + assert.spy(spawn.curl).was_called(1) + assert.spy(spawn.wget).was_called_with { + { + "--header", + "User-Agent: nvim-lsp-installer (+https://github.com/williamboman/nvim-lsp-installer)", + }, + "-nv", + "-O", + "-", + "https://api.github.com", + } + assert.spy(spawn.curl).was_called_with { + { "-H", "User-Agent: nvim-lsp-installer (+https://github.com/williamboman/nvim-lsp-installer)" }, + "-fsSL", + "https://api.github.com", + } + end) + ) + + it( + "should return stdout", + async_test(function() + stub(spawn, "wget") + spawn.wget.returns(Result.success { + stdout = [[{"data": "here"}]], + }) + local result = fetch "https://api.github.com/data" + assert.is_true(result:is_success()) + assert.equals([[{"data": "here"}]], result:get_or_throw()) + end) + ) +end) |
