0

テストしたい非同期ペデスタルインターセプターがあります。

(def my-interceptor
  (io.pedestal.interceptor/interceptor
    {:name  :my-interceptor
     :enter (fn [context]
              (as/go
                (do
                  (Thread/sleep 1000)
                  (assoc context :answer 42))))}))

私は最初に単純なテストを試みました:

(deftest my-test
  (is (= 42
         (:answer (io.pedestal.interceptor.chain/execute {} [my-interceptor])))))

非同期インターセプターがある場合にchain/execute戻るため、これは機能しません。nilテストしたものの直後にインターセプターにテストを追加する別のソリューションを試しました:

(deftest my-test
  (io.pedestal.interceptor.chain/execute
    {}
    [my-interceptor
     (io.pedestal.interceptor/interceptor
       {:name  :test
        :enter (fn [context]
                 (is (= 41 (:answer context))) ; should fail
                 context)})]))

ただし、テストが実行される前にテストが終了し、成功するため、これは機能しません。テストが 1 秒後に失敗しても、次のようになります。

Ran 1 test containing 0 assertions.
No failures.

FAIL in (my-test) (somefile_test.clj:49)
expected: (= 41 (:answer context))
  actual: (not (= 41 42))

実際には、私のテスト スイート (Kaocha を使用) はdeftest、アサーションのない があるため失敗します。

chain/executeそれがチャンではなく返されることを考えると、それが終了するまで to ブロックnilでラップすることはできません。as/<!!

この時点で私は立ち往生しています。そのようなインターセプターをテストするためにできることはありますか?

4

1 に答える 1