Fosi Fossil Service
Small teams. Open source. Built on Fossil.

CaaS / Lamina

Unified Management for Fossil Repositories

Public | Owner: CaaS | Default branch: trunk | Last update: 2026-10-25 00:41

Artifact 7dbd6610e2dc96b7531d3c48c984cc0b69618b5f04b24fdc583a32daa1e96bd1:


(defmodule lamina_config_tests
  (export all)
  (include-lib "eunit/include/eunit.hrl"))

;;---- load ----

(defun load_ok_test ()
  (let* ((dir (tmpdir))
         (path (filename:join dir "lamina.conf")))
    (file:write_file path "{site_name, \"mysite\"}.\n{db_path, \"x.db\"}.\n")
    (let ((result (lamina_config:load path)))
      (file:del_dir_r dir)
      (case result
        (`#(ok ,conf)
         (progn
           (=:= "mysite" (maps:get 'site_name conf))
           (=:= "x.db" (maps:get 'db_path conf))
           'ok))
        (other (fail_msg (lists:flatten (io_lib:format "unexpected: ~p" (list other)))))))))

(defun load_missing_file_test ()
  (case (lamina_config:load "/nonexistent/lamina.conf")
    (`#(error ,reason)
     (if (=:= 'consult-failed (element 1 reason))
         'ok
         (fail_msg (lists:flatten (io_lib:format "unexpected: ~p" (list reason))))))
    (other (fail_msg (lists:flatten (io_lib:format "unexpected: ~p" (list other)))))))

(defun load_bad_term_test ()
  (let* ((dir (tmpdir))
         (path (filename:join dir "bad.conf")))
    (file:write_file path "{site_name, \"unterminated\".\n")
    (let ((result (lamina_config:load path)))
      (file:del_dir_r dir)
      (case result
        (`#(error ,reason)
         (if (=:= 'consult-failed (element 1 reason))
             'ok
             (fail_msg (lists:flatten (io_lib:format "unexpected: ~p" (list reason))))))
        (other (fail_msg (lists:flatten (io_lib:format "unexpected: ~p" (list other)))))))))

(defun load_bad_fossil_bin_test ()
  (let* ((dir (tmpdir))
         (path (filename:join dir "badbin.conf")))
    (file:write_file path "{fossil_bin, \"/no/such/fossil\"}.\n")
    (let ((result (lamina_config:load path)))
      (file:del_dir_r dir)
      (case result
        (`#(error ,reason)
         (if (=:= 'fossil-bin-not-found (element 1 reason))
             'ok
             (fail_msg (lists:flatten (io_lib:format "unexpected: ~p" (list reason))))))
        (other (fail_msg (lists:flatten (io_lib:format "unexpected: ~p" (list other)))))))))

;;---- get ----

(defun get_with_default_test ()
  (lamina_config:put #M())
  (=:= "fallback" (lamina_config:get 'nope "fallback")))

(defun get_existing_test ()
  (lamina_config:put #M(site_name "abc"))
  (=:= "abc" (lamina_config:get 'site_name "z")))

;;---- fossil bin ----

(defun fossil_bin_resolves_test ()
  ;; 测试环境 PATH 中应有 fossil(本仓库即用 fossil 管理)
  (let ((bin (lamina_config:fossil-bin)))
    (if (is_atom bin)
        (eunit:fail "fossil not resolved from PATH")
        'ok)))

;;---- helpers ----

(defun tmpdir ()
  (let* ((cwd (element 2 (file:get_cwd)))
         (base (filename:join cwd "_build/tmp")))
    (filelib:ensure_dir (filename:join base "x"))
    (let* ((name (integer_to_list (element 3 (os:timestamp))))
           (dir (filename:join base name)))
      (file:make_dir dir)
      dir)))

(defun fail_msg (msg)
  (erlang:error (list_to_binary msg)))

Clone

You can clone this repository with the following command:

fossil clone https://fosi.dev/CaaS/Lamina

Contribute

The best way to contribute is through e-mail. See the project documentation for more details.