fix: revert dev
This commit is contained in:
parent
f846155ee5
commit
2b75843dab
4 changed files with 160 additions and 12 deletions
|
|
@ -124,6 +124,100 @@ describe('sync', function()
|
|||
end)
|
||||
end)
|
||||
|
||||
describe('register_backend', function()
|
||||
it('registers a custom backend', function()
|
||||
pending.register_backend({ name = 'custom', pull = function() end })
|
||||
local set = pending.sync_backend_set()
|
||||
assert.is_true(set['custom'] == true)
|
||||
assert.is_true(vim.tbl_contains(pending.sync_backends(), 'custom'))
|
||||
end)
|
||||
|
||||
it('rejects backend without name', function()
|
||||
local msg
|
||||
local orig = vim.notify
|
||||
vim.notify = function(m, level)
|
||||
if level == vim.log.levels.ERROR then
|
||||
msg = m
|
||||
end
|
||||
end
|
||||
pending.register_backend({})
|
||||
vim.notify = orig
|
||||
assert.truthy(msg and msg:find('non%-empty'))
|
||||
end)
|
||||
|
||||
it('rejects backend with empty name', function()
|
||||
local msg
|
||||
local orig = vim.notify
|
||||
vim.notify = function(m, level)
|
||||
if level == vim.log.levels.ERROR then
|
||||
msg = m
|
||||
end
|
||||
end
|
||||
pending.register_backend({ name = '' })
|
||||
vim.notify = orig
|
||||
assert.truthy(msg and msg:find('non%-empty'))
|
||||
end)
|
||||
|
||||
it('rejects duplicate of built-in backend', function()
|
||||
local msg
|
||||
local orig = vim.notify
|
||||
vim.notify = function(m, level)
|
||||
if level == vim.log.levels.ERROR then
|
||||
msg = m
|
||||
end
|
||||
end
|
||||
pending.register_backend({ name = 'gcal' })
|
||||
vim.notify = orig
|
||||
assert.truthy(msg and msg:find('already exists'))
|
||||
end)
|
||||
|
||||
it('rejects duplicate registered backend', function()
|
||||
pending.register_backend({ name = 'dup_test', pull = function() end })
|
||||
local msg
|
||||
local orig = vim.notify
|
||||
vim.notify = function(m, level)
|
||||
if level == vim.log.levels.ERROR then
|
||||
msg = m
|
||||
end
|
||||
end
|
||||
pending.register_backend({ name = 'dup_test' })
|
||||
vim.notify = orig
|
||||
assert.truthy(msg and msg:find('already registered'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('resolve_backend', function()
|
||||
it('resolves built-in backend', function()
|
||||
local mod = pending.resolve_backend('gcal')
|
||||
assert.is_not_nil(mod)
|
||||
assert.are.equal('gcal', mod.name)
|
||||
end)
|
||||
|
||||
it('resolves registered backend', function()
|
||||
local custom = { name = 'resolve_test', pull = function() end }
|
||||
pending.register_backend(custom)
|
||||
local mod = pending.resolve_backend('resolve_test')
|
||||
assert.is_not_nil(mod)
|
||||
assert.are.equal('resolve_test', mod.name)
|
||||
end)
|
||||
|
||||
it('returns nil for unknown backend', function()
|
||||
assert.is_nil(pending.resolve_backend('nonexistent_xyz'))
|
||||
end)
|
||||
|
||||
it('dispatches command to registered backend', function()
|
||||
local called = false
|
||||
pending.register_backend({
|
||||
name = 'cmd_test',
|
||||
pull = function()
|
||||
called = true
|
||||
end,
|
||||
})
|
||||
pending.command('cmd_test pull')
|
||||
assert.is_true(called)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('auto-discovery', function()
|
||||
it('discovers gcal and gtasks backends', function()
|
||||
local backends = pending.sync_backends()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue