add spec to yaml.clj and base64.clj

This commit is contained in:
az 2021-10-31 08:51:03 +01:00
parent 46a6ef85a6
commit 7713afdb38
2 changed files with 25 additions and 12 deletions

View file

@ -1,14 +1,21 @@
(ns dda.c4k-common.base64
(:import (java.util Base64)))
(:import (java.util Base64))
(:require
[orchestra.core :refer [defn-spec]]
[orchestra.spec.test :as st]
[clojure.spec.alpha :as s]))
(defn encode
[string]
(defn-spec encode string?
[string string?]
(.encodeToString
(Base64/getEncoder)
(.getBytes string "UTF-8")))
(defn decode
[string]
(defn-spec decode string?
[string string?]
(String.
(.decode (Base64/getDecoder) string)
"UTF-8"))
"UTF-8"))
(st/instrument)

View file

@ -2,18 +2,22 @@
(:require
[clojure.java.io :as io]
[clj-yaml.core :as yaml]
[clojure.walk]))
[clojure.walk]
[orchestra.core :refer [defn-spec]]
[orchestra.spec.test :as st]
[clojure.spec.alpha :as s]))
(defn cast-lazy-seq-to-vec
[lazy-seq]
(defn-spec cast-lazy-seq-to-vec map?
[lazy-seq map?]
(clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %)
(into [] %)
%) lazy-seq))
(defn from-string [input]
(defn-spec from-string map? [input string?]
(cast-lazy-seq-to-vec (yaml/parse-string input)))
(defn to-string [edn]
(defn-spec to-string string? [edn map?]
(yaml/generate-string edn :dumper-options {:flow-style :block}))
(defn dispatch-by-resource-name
@ -23,4 +27,6 @@
(defmulti load-resource dispatch-by-resource-name)
(defmethod load-resource :clj [resource-name]
(slurp (io/resource resource-name)))
(slurp (io/resource resource-name)))
(st/instrument)