|
483 | 483 | ;; Cross-database reset! tests |
484 | 484 | ;; ============================================================================= |
485 | 485 |
|
486 | | -(deftest reset-with-islot-value-test |
487 | | - (testing "reset! throws when using ISlot values from a different database" |
488 | | - (with-open [db1 (xdb/xit-db :memory) |
489 | | - db2 (xdb/xit-db :memory)] |
490 | | - ;; Set up first database with some data |
491 | | - (reset! db1 {:users [{:name "Alice"} {:name "Bob"}] |
492 | | - :config {:theme "dark"}}) |
493 | | - |
494 | | - ;; Get the value from db1 (which implements ISlot) |
495 | | - (let [val-from-db1 @db1] |
496 | | - ;; Attempting to reset db2 with an ISlot from db1 should throw |
497 | | - (is (thrown? IllegalArgumentException (reset! db2 val-from-db1)))))) |
498 | | - |
499 | | - (testing "reset! works when materializing the value first" |
500 | | - (with-open [db1 (xdb/xit-db :memory) |
501 | | - db2 (xdb/xit-db :memory)] |
502 | | - (reset! db1 {:users [{:name "Alice"} {:name "Bob"}] |
503 | | - :config {:theme "dark"}}) |
504 | | - |
505 | | - ;; Materialize the value before passing to reset! |
506 | | - (reset! db2 (tu/materialize @db1)) |
507 | | - |
508 | | - ;; db2 should now have the same data |
509 | | - (is (= (tu/materialize @db1) (tu/materialize @db2)))))) |
510 | | - |
511 | 486 | (deftest reset-with-nested-islot-value-test |
512 | | - (testing "reset! throws when using nested ISlot values from a different database" |
513 | | - (with-open [db1 (xdb/xit-db :memory) |
514 | | - db2 (xdb/xit-db :memory)] |
515 | | - (reset! db1 {:data [[1 2 3] [4 5 6] [7 8 9]]}) |
516 | | - |
517 | | - ;; Get a nested value that implements ISlot |
518 | | - (let [nested-val (get @db1 :data)] |
519 | | - ;; Attempting to reset db2 with an ISlot from db1 should throw |
520 | | - (is (thrown? IllegalArgumentException (reset! db2 nested-val)))))) |
521 | | - |
522 | 487 | (testing "reset! works with nested values when materializing first" |
523 | 488 | (with-open [db1 (xdb/xit-db :memory) |
524 | 489 | db2 (xdb/xit-db :memory)] |
|
0 commit comments