Links test cleanup

While debugging #8721 I noticed there was some opportunity for cleaning up and writing another test for this functionality.

* new test to ensure hosts files are being injected properly
* refactoring some common functionality into methods.

/cc @tiborvass @LK4D4