Fork me on GitHub
#biff
<
2023-05-01
>
jamesmintram21:05:09

Hey, came across biff today. Looks really cool. I started playing with it, and wondered what the best approach would be to writing tests involving the DB? Would speculative transactions be the way to go? or something else?

🙌 1
Jacob O'Bryant21:05:09

Yes, speculative transactions are a good way to go. I have a few tests for the biff/submit-tx function you can use as a starting point: https://github.com/jacobobryant/biff/blob/master/test/com/biffweb/impl/xtdb_test.clj (There are a couple tests in there that use with-tx, though most of the tests just set up a test db and run some queries)

Jacob O'Bryant21:05:05

I guess the main thing is you can set up an in-memory node/db with dummy data and then use it however you like, whether that means speculative transactions, queries, or even regular transactions + await-tx

jamesmintram21:05:58

Hmm, that would mean "bypassing" the biff/tx wrapper right?

jamesmintram21:05:35

biff/submit-tx

Jacob O'Bryant21:05:17

If you do speculative transactions, yes. So actually perhaps just calling biff/submit-tx on the in-memory node would be the way to go.

jamesmintram21:05:55

Would you use fixtures to setup an in memory DB/publish schema between each test?

jamesmintram21:05:44

I see you use (defn test-node [docs] for a lot of your tests

jamesmintram21:05:05

I assume this is just starting up an in-memory node.

👍 1
Jacob O'Bryant21:05:13

I would copy and paste test-node, schema and malli-optsfrom the file I linked, then follow the (with-open [node ... pattern

Jacob O'Bryant21:05:47

for calling submit-tx you can do (biff/submit-tx {:biff.xtdb/node node, :biff/malli-opts malli-opts} ...) , then call (xt/db node) to get a db value that includes the submitted transaction.

jamesmintram21:05:22

Is there a good way for higher level (integration(ish)) tests? like, set everything up, trigger a route, tear it all down again. Potentially in parallel with other tests doing similar stuff?

jamesmintram21:05:21

I guess it would be some variant of the default start method - returning a system you can use for a test/set of tests

Jacob O'Bryant21:05:00

I haven't set up any tests like that myself (I honestly just do manual testing for the most part), so it's not a beaten path so to speak, but yes if you create an alternate start fn that should do the trick.

jamesmintram21:05:32

Nice, thanks 👍 - gonna have a play around with this.

Jacob O'Bryant21:05:54

Sounds good! Let me know how it goes. I would like to flesh out the (mostly nonexistent) testing story at some point; it wouldn't hurt to have some more stuff built in.