-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Currently selecting is helpful to create tailored schemas:
(ms/select Person ^:only [:name :age {:country [:iso]}])But when used to generate data you often may want to set the properties of some attributes to make it an actually helpful generator for the test/context you'r working on.
So:
;; we'd want to turn this...
[:map [:name string?] [:age pos-int?] :country [:map [:iso string?]]]
;; ...into this:
[:map
[:name {:gen/return "Gert"} string?]
[:age [:int {:min 18 :max 50}]]
[:country
[:map
[:iso {:gen/elements ["NL" "DK"]} string?]]]]Sketching:
(-> Person
(ms/select ^:only [:name :age {:country [:iso]}])
(ms/merge-in-properties [:name] {:gen/return "Gert"})
(ms/merge-in-properties [:age] {:min 18 :max 50})
(ms/merge-in-properties [:country iso] {:gen/elements ["NL" "DK"]})
(mg/generate)) ;; => {:name "Gert" :age 21 :country "DK"}or even:
(-> Person
(ms/select ^:only [:name :age {:country [:iso]}])
(ms/merge-in-properties [[:name {:gen/return "Gert"}]
[:age {:min 18 :max 50}]
[:country [:iso {:gen/elements ["NL" "DK"]}]]])
(mg/generate)) ;; => {:name "Gert" :age 21 :country "DK"}Metadata
Metadata
Assignees
Labels
No labels