@@ -3,13 +3,7 @@ Package testurl makes URL generation in Go tests a breeze—no more boilerplate
33url.Parse calls or manual query-string concat. Simply import testurl and pick
44the helper you need to focus on your test logic, not the URL plumbing.
55
6- github.com/madflojo/testlazy/things/testurl
7-
8- What’s inside?
9-
10- - HTTP vs HTTPS for example.com and localhost.
11- - Ports, paths, queries, and fragments.
12- - Intentionally broken URLs for negative testing.
6+ github.com/madflojo/testlazy/things/testurl
137
148Example usage
159
@@ -30,6 +24,8 @@ import (
3024const (
3125 ExampleHost = "example.com"
3226 LocalhostHost = "localhost"
27+ HTTPPort = "8080"
28+ HTTPSPort = "8443"
3329)
3430
3531// URLHTTPBad returns a *url.URL for "http://bad-url" which is technically valid but "should" not resolve correctly.
@@ -69,12 +65,12 @@ func URLHTTPS() *url.URL {
6965
7066// URLHTTPWithPort returns a *url.URL for "http://example.com:8080/".
7167func URLHTTPWithPort () * url.URL {
72- return MustParse ("http://" + ExampleHost + ":8080 /" )
68+ return MustParse ("http://" + ExampleHost + ":" + HTTPPort + " /" )
7369}
7470
7571// URLHTTPSWithPort returns a *url.URL for "https://example.com:8443/".
7672func URLHTTPSWithPort () * url.URL {
77- return MustParse ("https://" + ExampleHost + ":8443 /" )
73+ return MustParse ("https://" + ExampleHost + ":" + HTTPSPort + " /" )
7874}
7975
8076// URLHTTPWithQuery returns a *url.URL for "http://example.com/?query=1".
@@ -129,12 +125,12 @@ func URLHTTPSLocalhost() *url.URL {
129125
130126// URLHTTPLocalhostWithPort returns a *url.URL for "http://localhost:8080/".
131127func URLHTTPLocalhostWithPort () * url.URL {
132- return MustParse ("http://" + LocalhostHost + ":8080 /" )
128+ return MustParse ("http://" + LocalhostHost + ":" + HTTPPort + " /" )
133129}
134130
135131// URLHTTPSLocalhostWithPort returns a *url.URL for "https://localhost:8443/".
136132func URLHTTPSLocalhostWithPort () * url.URL {
137- return MustParse ("https://" + LocalhostHost + ":8443 /" )
133+ return MustParse ("https://" + LocalhostHost + ":" + HTTPSPort + " /" )
138134}
139135
140136// MustParse is a helper function that parses a URL string and panics if it fails.
0 commit comments