1
- local child = MiniTest .new_child_neovim ()
1
+ local child_helper = require (" tests.child_helper" )
2
+ local child = child_helper .new_child_neovim (" test_auth" )
2
3
local u = require (" tests.utils" )
3
- local env = require (" tests.env" )
4
4
5
5
local config_path = require (" copilot.auth" ).find_config_path ()
6
6
local config_path_renamed = config_path .. " _temp_renamed"
7
7
8
8
local T = MiniTest .new_set ({
9
9
hooks = {
10
10
pre_once = function ()
11
- if vim .fn .filereadable (" ./tests/logs/test_auth.log" ) == 1 then
12
- vim .fn .delete (" ./tests/logs/test_auth.log" )
13
- end
14
-
15
11
if vim .fn .isdirectory (config_path ) == 1 then
16
12
vim .fn .rename (config_path , config_path_renamed )
17
13
end
18
14
end ,
19
15
pre_case = function ()
20
- child .restart ({ " -u " , " tests/scripts/minimal_init.lua " } )
16
+ child .run_pre_case ( )
21
17
child .lua (" M = require('copilot')" )
22
18
child .lua (" c = require('copilot.client')" )
23
19
child .lua (" s = require('copilot.status')" )
24
20
child .lua (" cmd = require('copilot.command')" )
25
21
child .lua (" a = require('copilot.api')" )
26
22
child .lua (" logger = require('copilot.logger')" )
23
+ child .fn .setenv (" GITHUB_COPILOT_TOKEN" , vim .NIL )
27
24
end ,
28
25
post_once = function ()
29
26
child .stop ()
@@ -37,43 +34,23 @@ local T = MiniTest.new_set({
37
34
38
35
T [" auth()" ] = MiniTest .new_set ()
39
36
40
- -- TODO: This test currently assumes you are not auth'd, so the token env var cannot be used
37
+ -- TODO: callback for this too
41
38
T [" auth()" ][" auth before attaching, should not give error" ] = function ()
42
- child .lua ([[ M.setup({
43
- logger = {
44
- file_log_level = vim.log.levels.TRACE,
45
- file = "./tests/logs/test_auth.log",
46
- trace_lsp = "verbose",
47
- log_lsp_messages = true,
48
- trace_lsp_progress = true,
49
- },
50
- })]] )
51
-
52
- vim .loop .sleep (500 )
39
+ child .configure_copilot ()
53
40
child .cmd (" Copilot auth" )
54
- vim .loop .sleep (500 )
41
+ vim .loop .sleep (3000 )
55
42
local messages = child .cmd_capture (" messages" )
56
- u .expect_match (messages , " .*Online.*Enabled .*" )
43
+ u .expect_match (messages , " .*Authenticated as GitHub user .*" )
57
44
end
58
45
59
46
T [" auth()" ][" auth issue replication" ] = function ()
60
- child .fn .setenv (" GITHUB_COPILOT_TOKEN" , env .COPILOT_TOKEN )
61
- child .lua ([[ M.setup({
62
- logger = {
63
- file_log_level = vim.log.levels.TRACE,
64
- file = "./tests/logs/test_auth.log",
65
- trace_lsp = "verbose",
66
- log_lsp_messages = true,
67
- trace_lsp_progress = true,
68
- },
69
- })]] )
70
-
71
- vim .loop .sleep (500 )
47
+ child .configure_copilot ()
72
48
child .cmd (" Copilot auth" )
73
- vim .loop .sleep (500 )
49
+ vim .loop .sleep (2000 )
74
50
child .cmd (" Copilot status" )
51
+ vim .loop .sleep (500 )
75
52
local messages = child .cmd_capture (" messages" )
76
- u .expect_match (messages , " .*Online.*Authenticated .*" )
53
+ u .expect_match (messages , " .*Online.*Enabled .*" )
77
54
end
78
55
79
56
return T
0 commit comments