dimanche 8 septembre 2019

Is there an (idiomatic) way of testing the result of an IO function in Clojure?

I have a function that saves some text to a file:

(defn save-keypair
  "saves keypair to ~/.ssb-clj/secret"
  [pair file-path]
  (let [public-key-string (->> (:public pair) (.array) (byte-array) (b64/encode) (bs/to-string))
        secret-key-string (->> (:secret pair) (.array) (byte-array) (b64/encode) (bs/to-string))]
    (spit file-path (str "Public Key: " public-key-string))
    (spit file-path (str "\nPrivate Key: " secret-key-string) :append true)))

It works fine (currently checking via just opening the file and looking at it myself). However, I'd like to write an actual test to check that everything is working correctly. Is there an idiomatic way of doing this in Clojure?

Aucun commentaire:

Enregistrer un commentaire