Refactor config_loading

And add unit tests

Change-Id: I02e45eaae4db4aab862324a246d9cb95eaad6c17
Reviewed-on: http://review.couchbase.org/34335
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>