-
Notifications
You must be signed in to change notification settings - Fork 4
/
rest_api_integration_module_test.clj
29 lines (26 loc) · 1.58 KB
/
rest_api_integration_module_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(ns rama.gallery.rest-api-integration-module-test
(:use [com.rpl rama]
[com.rpl.rama path])
(:require
[clojure.test :refer [deftest is testing]]
[com.rpl.rama.test :as rtest]
[rama.gallery.rest-api-integration-module :as raim]))
(deftest rest-api-integration-module-test
;; create-ipc creates an InProcessCluster which simulates a full Rama cluster in-process and is an ideal environment for
;; experimentation and unit-testing.
(with-open [ipc (rtest/create-ipc)]
(rtest/launch-module! ipc raim/RestAPIIntegrationModule {:tasks 4 :threads 2})
(let [module-name (get-module-name raim/RestAPIIntegrationModule)
;; Client usage of IPC is identical to using a real cluster. Depot and PState clients are fetched by
;; referencing the module name along with the variable used to identify the depot/PState within the module.
get-depot (foreign-depot ipc module-name "*get-depot")
responses (foreign-pstate ipc module-name "$$responses")
url "https://official-joke-api.appspot.com/random_joke"]
;; This checks the behavior of the module by appending a few URLs and printing the responses recorded in the
;; PState. To write a real test with actual assertions, it's best to test the behavior of the module with
;; the external REST API calls mocked out, such as by using with-redefs.
(foreign-append! get-depot url)
(println "Response 1:" (foreign-select-one (keypath url) responses))
(foreign-append! get-depot url)
(println "Response 2:" (foreign-select-one (keypath url) responses))
)))