libraries/singularity: refactor DB config loading into a function

Added lots of tests