Mocking Vault for unit tests in Go

938 views
Skip to first unread message

Jonathan Turner

unread,
Aug 9, 2017, 1:09:56 PM8/9/17
to Vault
Hi,

I've been writing an application in Go that uses Vault and I was looking for a way to mock out Vault for unit tests.

I created https://github.com/jcmturner/vaultmock but I have come across a problem that the Vault github repo also includes sql driver libraries in its vendors directory. This leads to a clash with my own use of registering sql drivers. This comes from the fact I'm having to import most of the Vault repo to create an in-memory mock of Vault.

I also have had to duplicate a lot of code as the methods are not publicly exported for use outside of the Vault packages. For example the testCoreConfig() from the github.com/hashicorp/vault/vault/testing.go file would be really helpful.

Is there any intention to develop a mock version of Vault that would be suitable for unit testing in Go applications?

Jeff Mitchell

unread,
Aug 9, 2017, 4:52:45 PM8/9/17
to Vault
Hi Jonathan,

We don't officially have a mock/testing version that we sort of put out there, and the reason is that first and foremost testing code needs to serve our own purposes and we need to feel free to change the API and so as needed.

That said, in almost all circumstances what you want to use from outside of Vault is NewTestCluster from the vault package. It gives you a fairly highly customizable (storage, available backends, etc.) three-node cluster complete with TLS, fully-set-up API clients, and more. Just keep in mind that it may change (but usually in ways that make it even better!).

Best,
Jeff

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/vault/issues
IRC: #vault-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Vault" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vault-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vault-tool/1491b985-8616-4464-880d-53b55b90deae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages