|
| 1 | +;;; eca-config-test.el --- Tests for eca-config -*- lexical-binding: t; -*- |
| 2 | +;;; Commentary: |
| 3 | +;;; Code: |
| 4 | + |
| 5 | +(require 'buttercup) |
| 6 | +(require 'f) |
| 7 | +(require 'eca-util) |
| 8 | +(require 'eca-config) |
| 9 | + |
| 10 | +(defvar eca-local-to-remote-prefix-map) |
| 11 | + |
| 12 | +(defun eca-config-test--env (&rest vars) |
| 13 | + "Return `process-environment' with VARS prepended. |
| 14 | +A VAR of the form \"NAME=VALUE\" sets NAME, a bare \"NAME\" unsets it." |
| 15 | + (append vars process-environment)) |
| 16 | + |
| 17 | +(describe "eca-config--global-path" |
| 18 | + (describe "with the path reported by the server" |
| 19 | + (it "uses it over the local resolution" |
| 20 | + (let ((session (make-eca--session |
| 21 | + :global-config-path "/srv/home/.config/eca/config.json" |
| 22 | + :workspace-folders '("/srv/project"))) |
| 23 | + (eca-local-to-remote-prefix-map nil) |
| 24 | + (process-environment (eca-config-test--env "XDG_CONFIG_HOME=/tmp/xdg"))) |
| 25 | + (expect (eca-config--global-path session) |
| 26 | + :to-equal "/srv/home/.config/eca/config.json"))) |
| 27 | + |
| 28 | + (it "applies the explicit prefix map" |
| 29 | + (let ((session (make-eca--session |
| 30 | + :global-config-path "/root/.config/eca/config.json" |
| 31 | + :workspace-folders '("/Users/me/dev/project"))) |
| 32 | + (eca-local-to-remote-prefix-map |
| 33 | + '(("/Users/me/eca-home" . "/root/.config/eca")))) |
| 34 | + (expect (eca-config--global-path session) |
| 35 | + :to-equal (expand-file-name "/Users/me/eca-home/config.json")))) |
| 36 | + |
| 37 | + (it "reuses the TRAMP prefix of remote workspace folders" |
| 38 | + (let ((session (make-eca--session |
| 39 | + :global-config-path "/home/me/.config/eca/config.json" |
| 40 | + :workspace-folders '("/docker:container:/workspace/project"))) |
| 41 | + (eca-local-to-remote-prefix-map nil)) |
| 42 | + (expect (eca-config--global-path session) |
| 43 | + :to-equal "/docker:container:/home/me/.config/eca/config.json"))) |
| 44 | + |
| 45 | + (it "does not prefix a path already translated from a TRAMP folder" |
| 46 | + (let ((session (make-eca--session |
| 47 | + :global-config-path "/workspace/project/eca/config.json" |
| 48 | + :workspace-folders '("/docker:container:/workspace/project"))) |
| 49 | + (eca-local-to-remote-prefix-map nil)) |
| 50 | + (expect (eca-config--global-path session) |
| 51 | + :to-equal "/docker:container:/workspace/project/eca/config.json")))) |
| 52 | + |
| 53 | + (describe "without a path from the server" |
| 54 | + (it "falls back to XDG_CONFIG_HOME when set" |
| 55 | + (let ((process-environment (eca-config-test--env "XDG_CONFIG_HOME=/tmp/xdg"))) |
| 56 | + (expect (eca-config--global-path (make-eca--session)) |
| 57 | + :to-equal (f-join "/tmp/xdg" "eca" "config.json")))) |
| 58 | + |
| 59 | + (it "falls back to ~/.config/eca/config.json" |
| 60 | + (let ((system-type 'gnu/linux) |
| 61 | + (process-environment (eca-config-test--env "XDG_CONFIG_HOME" |
| 62 | + "USERPROFILE=/Users/other"))) |
| 63 | + (expect (eca-config--global-path) |
| 64 | + :to-equal (f-join (f-expand "~") ".config" "eca" "config.json")))) |
| 65 | + |
| 66 | + (it "uses USERPROFILE on Windows like the server's user.home" |
| 67 | + (let ((system-type 'windows-nt) |
| 68 | + (process-environment (eca-config-test--env "XDG_CONFIG_HOME" |
| 69 | + "USERPROFILE=/Users/me"))) |
| 70 | + (expect (eca-config--global-path) |
| 71 | + :to-equal (f-join "/Users/me" ".config" "eca" "config.json")))))) |
| 72 | + |
| 73 | +(provide 'eca-config-test) |
| 74 | +;;; eca-config-test.el ends here |
0 commit comments