git » dnss » commit 79e7e85

httpresolver: Make invalid server test even more hermetic

author Alberto Bertogli
2022-07-03 11:40:26 UTC
committer Alberto Bertogli
2022-07-03 11:40:26 UTC
parent 61ea47a6094d4b06d49e925507fd7e356925929c

httpresolver: Make invalid server test even more hermetic

Currently, the invalid server test contacts 0.0.0.0, which unfortunately
is taken as localhost:80, and if there is a valid web server running
there, the test fails.

This patch fixes the problem by creating a test server, closing it, and
then attempting to contact it. That should be much more hermetic and
independent from the testing environment.

internal/httpresolver/resolver_test.go +4 -1

diff --git a/internal/httpresolver/resolver_test.go b/internal/httpresolver/resolver_test.go
index c847b28..276fa61 100644
--- a/internal/httpresolver/resolver_test.go
+++ b/internal/httpresolver/resolver_test.go
@@ -89,7 +89,10 @@ func TestBasic(t *testing.T) {
 }
 
 func TestInvalidServer(t *testing.T) {
-	r := mustNewDoH(t, "http://0.0.0.0/")
+	ts := httptest.NewServer(nil)
+	ts.Close()
+
+	r := mustNewDoH(t, ts.URL)
 	queryExpectErr(t, r, "test.blah.", "POST failed:")
 }