Question: In a test, with the testutil.StartCerbos...
# help
r
Question: In a test, with the testutil.StartCerbosServer() server, I get
request failed: rpc error: code = Internal desc = Policy check failed
. I'm sure it's a silly mistake I made, but how do I get the test server to log the actual error to further debug?
c
That's an interesting question. I am not sure whether it's possible. I'll try a few things and get back to you.
Turns out it's possible. You need to replace the Zap logger in your test. Here's what I did:
Copy code
logger := zaptest.NewLogger(t)
zap.ReplaceGlobals(logger)
Full code listing is on this gist: https://gist.github.com/charithe/f060269f676fde8f8a54374cf8a36eea
r
Nice one!! I'll try it out 😎 thanks 😄
So it seems that my in-memory SQLite somehow got mixed up with another in-memory sqlite database, even though that database should be isolated:
Copy code
failed to get check for [john.default]: failed to get compilation units: SQL logic error: no such table: policy_ancestor (1)
When I changed
:memory:
to
file:CERBOS?mode=memory&cache=shared&_fk=1
it started working consistently. I'm not entirely sure what the difference is, but the latter is what I usually use for in-memory sqlites (as I didn't know about the first option).
c
:memory:
should be a distinct database according to https://www.sqlite.org/inmemorydb.html 🤔 Not sure why that didn't work. Anyway, I am glad you found a fix.
r
it was only a specific test failing, and I couldn't really reproduce it. I had two almost exactly identical tests where one was failing with that error and the other wasn't. I guess its one of those magical cases where you just need to do this: 🙈
g
nothing to see here