Skip to content

Commit 69f8b3b

Browse files
committed
Fix the fixed unit test
1 parent fec258e commit 69f8b3b

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/xitdb/db.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
(when (not= db coll-db)
5555
(throw (IllegalArgumentException. "Cannot write value from a different database")))
5656
(.write cursor (common/-slot new-value)))
57-
(conversion/v->slot! cursor new-value)))
57+
(.write cursor (conversion/v->slot! cursor new-value))))
5858

5959
(defn xitdb-reset!
6060
"Sets the value of the database to `new-value`.

test/xitdb/branch_features_test.clj

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
;; =============================================================================
195195

196196
(deftest reset-with-islot-value-test
197-
(testing "reset! can use ISlot values directly"
197+
(testing "reset! throws when using ISlot values from a different database"
198198
(with-open [db1 (xdb/xit-db :memory)
199199
db2 (xdb/xit-db :memory)]
200200
;; Set up first database with some data
@@ -203,20 +203,39 @@
203203

204204
;; Get the value from db1 (which implements ISlot)
205205
(let [val-from-db1 @db1]
206-
;; Reset db2 with the ISlot value
207-
(reset! db2 val-from-db1)
206+
;; Attempting to reset db2 with an ISlot from db1 should throw
207+
(is (thrown? IllegalArgumentException (reset! db2 val-from-db1))))))
208208

209-
;; db2 should now have the same data
210-
(is (= (tu/materialize @db1) (tu/materialize @db2)))))))
209+
(testing "reset! works when materializing the value first"
210+
(with-open [db1 (xdb/xit-db :memory)
211+
db2 (xdb/xit-db :memory)]
212+
(reset! db1 {:users [{:name "Alice"} {:name "Bob"}]
213+
:config {:theme "dark"}})
214+
215+
;; Materialize the value before passing to reset!
216+
(reset! db2 (tu/materialize @db1))
217+
218+
;; db2 should now have the same data
219+
(is (= (tu/materialize @db1) (tu/materialize @db2))))))
211220

212221
(deftest reset-with-nested-islot-value-test
213-
(testing "reset! with nested ISlot values preserves structure"
222+
(testing "reset! throws when using nested ISlot values from a different database"
214223
(with-open [db1 (xdb/xit-db :memory)
215224
db2 (xdb/xit-db :memory)]
216225
(reset! db1 {:data [[1 2 3] [4 5 6] [7 8 9]]})
217226

218227
;; Get a nested value that implements ISlot
219228
(let [nested-val (get @db1 :data)]
229+
;; Attempting to reset db2 with an ISlot from db1 should throw
230+
(is (thrown? IllegalArgumentException (reset! db2 nested-val))))))
231+
232+
(testing "reset! works with nested values when materializing first"
233+
(with-open [db1 (xdb/xit-db :memory)
234+
db2 (xdb/xit-db :memory)]
235+
(reset! db1 {:data [[1 2 3] [4 5 6] [7 8 9]]})
236+
237+
;; Materialize the nested value before passing to reset!
238+
(let [nested-val (tu/materialize (get @db1 :data))]
220239
(reset! db2 nested-val)
221240
(is (= [[1 2 3] [4 5 6] [7 8 9]] (tu/materialize @db2)))))))
222241

@@ -408,15 +427,15 @@
408427
(is (= 2 (get (xdb/deref-at db 3) :value))))))
409428

410429
(deftest reset-preserves-data-integrity-test
411-
(testing "reset! with ISlot values from another database preserves data integrity"
430+
(testing "reset! with materialized values from another database preserves data integrity"
412431
(with-open [db1 (xdb/xit-db :memory)
413432
db2 (xdb/xit-db :memory)]
414433
;; Create large nested data
415434
(reset! db1 {:data (vec (range 100))
416435
:nested {:more (vec (range 50))}})
417436

418-
;; Reset db2 with the value (materializes for cross-database safety)
419-
(reset! db2 @db1)
437+
;; Materialize the value before passing to reset! (required for cross-database)
438+
(reset! db2 (tu/materialize @db1))
420439

421440
;; Verify data integrity
422441
(is (= (tu/materialize @db1) (tu/materialize @db2)))

0 commit comments

Comments
 (0)