File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,13 @@ func unsetEnv(key string) func() {
61
61
62
62
func TestHTTPProbeProxy (t * testing.T ) {
63
63
res := "welcome to http probe proxy"
64
- localProxy := "http://127.0.0.1:9098/"
64
+
65
+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
66
+ fmt .Fprint (w , res )
67
+ }))
68
+ defer server .Close ()
69
+
70
+ localProxy := server .URL
65
71
66
72
defer setEnv ("http_proxy" , localProxy )()
67
73
defer setEnv ("HTTP_PROXY" , localProxy )()
@@ -71,16 +77,6 @@ func TestHTTPProbeProxy(t *testing.T) {
71
77
followNonLocalRedirects := true
72
78
prober := New (followNonLocalRedirects )
73
79
74
- go func () {
75
- http .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
76
- fmt .Fprint (w , res )
77
- })
78
- err := http .ListenAndServe (":9098" , nil )
79
- if err != nil {
80
- t .Errorf ("Failed to start foo server: localhost:9098" )
81
- }
82
- }()
83
-
84
80
// take some time to wait server boot
85
81
time .Sleep (2 * time .Second )
86
82
url , err := url .Parse ("http://example.com" )
You can’t perform that action at this time.
0 commit comments