testing

Testing tools, testing philosophy & methodology...
Daniel Wellman 2021-04-20T19:16:47.080100Z

I’m experimenting with vcr-clj (https://github.com/gfredericks/vcr-clj) and have noticed that the “cassette” text files appear to have an encoded response body, which means you can’t look at the cassettes to understand what the response says (assuming a JSON text response). Does anyone know of a way to make vcr-clj keep the response as unencoded text?

jumar 2021-04-21T09:45:26.080400Z

I'm not sure if there's an option for that - it will try to "Base64 encode" the response body to make it serializable. You can write some utility functions to decode that, e.g. https://github.com/jumarko/clojure-experiments/blob/master/src/clojure_experiments/networking.clj#L66-L88

(defn decode-body [base64-encoded-strings]
   (-> base64-encoded-strings
       vcr-serialization/maybe-join
       codec/base64-decode
       (String.)))

  (with-open [r (java.io.PushbackReader. (io/reader (vcr-cassettes/cassette-file :record)))]
   (let [as-edn (edn/read {:readers  (assoc vcr-serialization/data-readers
                                            'vcr-clj/input-stream decode-body)}
                          r)
         body (-> as-edn :calls (get 0) :return :body)]
     (println body)))
    ,)