                      (after :facts (clean-cache!))]
   (fact "about BAM indexer (medium file)" :slow
         (bai/create-index
-          temp-file-sorted (str temp-file-sorted ".bai")) => anything))
+          temp-file-sorted (str temp-file-sorted ".bai")) => anything
+          (.exists (file (str temp-file-sorted ".bai"))) => truthy))
 
 (with-state-changes [(before :facts (do (prepare-cavy!)
                                         (prepare-cache!)

                     (after :facts (clean-cache!))]
  (fact "about BAM indexer (large file)" :slow
        (bai/create-index
          temp-file-sorted (str temp-file-sorted ".bai")) => anything))


  (fact "about BAM indexer"
        (bai/create-index
          temp-file-sorted (str temp-file-sorted ".bai")) => anything
        (.exists (file (str temp-file-sorted ".bai"))) => truthy
        (with-open [r (bam/reader temp-file-sorted)]
          (io/read-alignments r {:chr "ref" :start 0 :end 1000})
          ) => (filter #(= "ref" (:rname %))
                       (:alignments test-sam-sorted-by-pos))))

(let [f (str temp-dir "/test.incomplete.bam")
      sorted-f (str temp-dir "/test.incomplete.sorted.bam")]
  (with-state-changes [(before :facts (do (prepare-cache!)
                                          ;; generate incomplete bam on the fly
                                          (spit-bam-for-test
                                            f test-sam-incomplete-alignments)
                                          ;; TODO: go independent from sorter
