aws-api provides a test double
implementation to test code that uses aws-api offline and even with no AWS
account. To use it, instrument a handler fn or literal response for every
op that will be invoked (via aws/invoke
or aws/invoke-async
) during a
test, e.g.
(require '[cognitect.aws.client.test-double :as test]
'[cognitect.aws.client.api :as aws])
;; implementation being tested
(defn do-something [s3-client]
(let [res (aws/invoke s3-client {:op :CreateBucket
:request {:Bucket "a-bucket"}})]
;; do stuff with res
))
;; test using a handler function
(let [test-s3-client
(test/client {:api :s3
:ops {:ListBuckets (fn [{:keys [op request] :as op-map}]
;; do stuff based on op-map
;; then, return a value
{:Location "def"})}})]
(let [res (do-something test-s3-client)]
;; make assertions about res
))
;; test using a literal response
(let [test-s3-client
(test/client {:api :s3
:ops {:CreateBucket {:Location "a-location"}}})]
(let [res (do-something test-s3-client)]
;; make assertions about res
))
;; instrument test client after initialization
(let [test-s3-client (test/client {:api :s3})]
(test/instrument test-s3-client {:CreateBucket {:Location "a-location"}})
(let [res (do-something test-s3-client)]
;; make assertions about res
)
(test/instrument test-s3-client {:CreateBucket {:Location "another-location"}})
(let [res (do-something test-s3-client)]
;; make assertions about res
))
Test Double is a general term for an object that doubles for a "real" object in a test. There are many types of test doubles and plenty of discussion about the costs/benefits of each, however, aside from explicitly supporting test stubs, we are not supporting any other type of test double directly. Handler functions, however, give you leverage to implement any other type of test double.
client
will throw when you instrument an op that is not supported by the service
invoke
will return an anomaly when
invoke-async
will put an anomaly on the channel it returns, following
the same conditions as invoke
invoke
, invoke-async
, and stop
functions supported
by the normal aws api clientclient
will not validate the response payloads you provideCan you improve this documentation? These fine people already did:
David Chelimsky & Maria Clara CrespoEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |