Mocking Consul from HTTP client

2,258 views
Skip to first unread message

Zac Herby

unread,
Sep 15, 2015, 10:53:55 AM9/15/15
to Consul
I'm building an HTTP client to Consul (Java) that will read/write KV pairs and service registrations to a specified Consul server.

In this library's automated tests, I'd like to mock Consul and was wondering if this community had any recommendations for me (perhaps there is some little known "embedded Consul" project or something like that)?

Any input/steering whatsoever is greatly appreciated!

Zac

Ryan Uber

unread,
Sep 17, 2015, 1:24:46 PM9/17/15
to consu...@googlegroups.com
Hey Zac,

While it's certainly possible to mock Consul's API responses, the route we took for Consul's own Go client was to just fork a new Consul server process and use the actual API's instead. We wrapped this into a little library that we used in a number of places, which you can see here: https://github.com/hashicorp/consul/tree/master/testutil. This won't directly solve your use case, but you could do something similar in Java, I imagine, and you'll spend less time trying to stub the world, especially as new releases of Consul are made with new API's.

Hope that helps in some way!
- Ryan

--
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/consul/issues
IRC: #consul on Freenode
---
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/consul-tool/4041726d-c914-41b9-a22b-1af3e6a5bf54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Seth Vargo

unread,
Sep 18, 2015, 5:50:34 AM9/18/15
to consu...@googlegroups.com
We also do the same thing in Consul Template and envconsul - just spin up a single Consul server in the bg :)

Best,
Seth

Zac Herby

unread,
Sep 23, 2015, 12:34:59 PM9/23/15
to Consul
Thanks guys! That sounds like the way to go.

Ryan Breen

unread,
Sep 23, 2015, 3:03:45 PM9/23/15
to consu...@googlegroups.com
If you are using Travis, you can copypasta this: https://github.com/Cimpress-MCP/fsconsul/blob/master/.travis.yml (though I now realize I'm overdue to update the versions I use).

Paweł Szymczyk

unread,
Jun 29, 2016, 3:33:17 PM6/29/16
to Consul
Hi Zac

I've created something which is perfect for you - embedded-consul https://github.com/pszymczyk/embedded-consul. It's simple Java library which provides easy way to run consul dev server in JVM stack. It provides JUnit rule or can be started manually.

Regars
Paweł Szymczyk
Reply all
Reply to author
Forward
0 new messages