|
| 1 | +local child = MiniTest.new_child_neovim() |
| 2 | +local u = require("tests.utils") |
| 3 | +local env = require("tests.env") |
| 4 | + |
| 5 | +local config_path = require("copilot.auth").find_config_path() |
| 6 | +local config_path_renamed = config_path .. "_temp_renamed" |
| 7 | + |
| 8 | +local T = MiniTest.new_set({ |
| 9 | + hooks = { |
| 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 | + if vim.fn.isdirectory(config_path) == 1 then |
| 16 | + vim.fn.rename(config_path, config_path_renamed) |
| 17 | + end |
| 18 | + end, |
| 19 | + pre_case = function() |
| 20 | + child.restart({ "-u", "tests/scripts/minimal_init.lua" }) |
| 21 | + child.lua("M = require('copilot')") |
| 22 | + child.lua("c = require('copilot.client')") |
| 23 | + child.lua("s = require('copilot.status')") |
| 24 | + child.lua("cmd = require('copilot.command')") |
| 25 | + child.lua("a = require('copilot.api')") |
| 26 | + child.lua("logger = require('copilot.logger')") |
| 27 | + end, |
| 28 | + post_once = function() |
| 29 | + child.stop() |
| 30 | + |
| 31 | + if vim.fn.isdirectory(config_path_renamed) == 1 then |
| 32 | + vim.fn.rename(config_path_renamed, config_path) |
| 33 | + end |
| 34 | + end, |
| 35 | + }, |
| 36 | +}) |
| 37 | + |
| 38 | +T["auth()"] = MiniTest.new_set() |
| 39 | + |
| 40 | +-- TODO: This test currently assumes you are not auth'd, so the token env var cannot be used |
| 41 | +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) |
| 53 | + child.cmd("Copilot auth") |
| 54 | + vim.loop.sleep(500) |
| 55 | + local messages = child.cmd_capture("messages") |
| 56 | + u.expect_match(messages, ".*Online.*Enabled.*") |
| 57 | +end |
| 58 | + |
| 59 | +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) |
| 72 | + child.cmd("Copilot auth") |
| 73 | + vim.loop.sleep(500) |
| 74 | + child.cmd("Copilot status") |
| 75 | + local messages = child.cmd_capture("messages") |
| 76 | + u.expect_match(messages, ".*Online.*Authenticated.*") |
| 77 | +end |
| 78 | + |
| 79 | +return T |
0 commit comments