From 88f590ce0e01767bcc8dfdc862a456efde77d4a0 Mon Sep 17 00:00:00 2001 From: William Boman Date: Mon, 11 Apr 2022 17:19:01 +0200 Subject: more async refactor (#587) --- tests/core/fetch_spec.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/core/fetch_spec.lua (limited to 'tests/core/fetch_spec.lua') 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) -- cgit v1.2.3-70-g09d2