Skip to content

Commit

Permalink
fix: check for kubeconfig path + kubectl exec before enabling mode (#159
Browse files Browse the repository at this point in the history
)

Closes #158.
  • Loading branch information
jinnovation authored Apr 2, 2024
1 parent 1726201 commit f67b959
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/references/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ versioning][semver].

## Unreleased

### Fixed

- Fixed a bug where `kele-mode` errors out when the kubeconfig file does not
exist yet

### Changed

- Bumped dependency `plz` from `0.3` to `0.4`
Expand Down
13 changes: 13 additions & 0 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -1198,10 +1198,23 @@ Only populated if Embark is installed.")
(dolist (entry kele--embark-keymap-entries)
(delete entry embark-keymap-alist)))))

(defun kele--precheck ()
"Return an error if `kele-mode' is not ready to be enabled.
Ensures various preconditions are met,
e.g. `kele-kubectl-executable' is actually present."

(when (not (executable-find kele-kubectl-executable))
(error "`%s' not found on PATH" kele-kubectl-executable))

(when (not (file-exists-p kele-kubeconfig-path))
(error "`%s' does not exist; set up kubectl properly and try again" kele-kubeconfig-path)))

(defun kele--enable ()
"Enables Kele functionality.
This is idempotent."
(kele--precheck)
(unless kele--enabled
(setq kele--enabled t)
;; FIXME: Update the watcher when `kele-kubeconfig-path' changes.
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/test-kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,23 @@ metadata:
(it "does nothing"
(kele-mode 1)
(expect 'kele--cache-start :not :to-have-been-called)
(expect 'kele--setup-embark-maybe :not :to-have-been-called))))
(expect 'kele--setup-embark-maybe :not :to-have-been-called)))
(describe "when `kele-kubectl-executable' not found"
(before-each
(spy-on 'executable-find
:and-call-fake
(lambda (exec)
(not (string-equal exec kele-kubectl-executable)))))
(it "throws error"
(expect (kele-mode 1) :to-throw 'error)))
(describe "when `kele-kubeconfig-path' does not exist"
(before-each
(spy-on 'file-exists-p
:and-call-fake
(lambda (f)
(not (string-equal f kele-kubeconfig-path)))))
(it "throws error"
(expect (kele-mode 1) :to-throw 'error))))
(describe "disabling"
(describe "when `kele--enabled' is nil"
(before-each
Expand Down

0 comments on commit f67b959

Please sign in to comment.