forked from zbirenbaum/copilot.lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_auth.lua
More file actions
132 lines (104 loc) · 3.18 KB
/
test_auth.lua
File metadata and controls
132 lines (104 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
local child_helper = require("tests.child_helper")
local child = child_helper.new_child_neovim("test_auth")
local u = require("tests.utils")
local config_path = require("copilot.auth").find_config_path() .. "/github-copilot"
local config_path_renamed = config_path .. "_temp_renamed"
--TODO: find a way to not mess with folders
local T = MiniTest.new_set({
hooks = {
pre_once = function()
if vim.fn.isdirectory(config_path) == 1 then
vim.fn.rename(config_path, config_path_renamed)
end
end,
pre_case = function()
child.run_pre_case()
end,
post_once = function()
child.stop()
if vim.fn.isdirectory(config_path_renamed) == 1 then
vim.fn.rename(config_path_renamed, config_path)
end
end,
},
})
T["auth()"] = MiniTest.new_set()
T["auth()"]["auth before attaching, should not give error"] = function()
child.configure_copilot()
child.cmd("Copilot auth")
local messages = child.lua([[
local messages = ""
local function has_passed()
messages = vim.api.nvim_exec("messages", { output = true }) or ""
return string.find(messages, ".*Authenticated as GitHub user.*") ~= nil
end
vim.wait(5000, function()
return has_passed()
end, 50)
return messages
]])
u.expect_match(messages, ".*Authenticated as GitHub user.*")
end
T["auth()"]["auth issue replication"] = function()
child.configure_copilot()
child.cmd("Copilot auth")
child.lua([[
local messages = ""
local function has_passed()
messages = vim.api.nvim_exec("messages", { output = true }) or ""
return string.find(messages, ".*Authenticated as GitHub user.*") ~= nil
end
vim.wait(5000, function()
return has_passed()
end, 50)
]])
child.cmd("Copilot status")
local messages = child.lua([[
local messages = ""
local function has_passed()
messages = vim.api.nvim_exec("messages", { output = true }) or ""
return string.find(messages, ".*Online.*") ~= nil
end
vim.wait(5000, function()
return has_passed()
end, 50)
return messages
]])
u.expect_match(messages, ".*Online.*")
end
T["auth()"]["is_authenticated when not authed returns false"] = function()
child.configure_copilot()
local result = child.lua([[
local auth = require("copilot.auth")
local auth_result = auth.is_authenticated()
return tostring(auth_result)
]])
u.expect_match(result, "false")
end
T["auth()"]["is_authenticated when authed returns true"] = function()
child.configure_copilot()
child.cmd("Copilot auth")
child.lua([[
local messages = ""
local function has_passed()
messages = vim.api.nvim_exec("messages", { output = true }) or ""
return string.find(messages, ".*Authenticated as GitHub user.*") ~= nil
end
vim.wait(5000, function()
return has_passed()
end, 50)
]])
local result = child.lua([[
local auth_result = ""
local function has_passed()
auth_result = require("copilot.auth").is_authenticated() or ""
return auth_result == true
end
vim.wait(5000, function()
return has_passed()
end, 50)
return tostring(auth_result)
]])
u.expect_match(result, "true")
end
return T