@@ -7,6 +7,7 @@ package client
7
7
import (
8
8
"fmt"
9
9
"io/ioutil"
10
+ "net"
10
11
"net/http"
11
12
"os"
12
13
"path"
@@ -93,7 +94,13 @@ func TestClient(t *testing.T) {
93
94
http .HandleFunc ("/golang.org/example/one.json" , serveTestVuln1 )
94
95
http .HandleFunc ("/golang.org/example/two.json" , serveTestVuln2 )
95
96
http .HandleFunc ("/index.json" , serveIndex )
96
- go func () { http .ListenAndServe (":8080" , nil ) }()
97
+
98
+ l , err := net .Listen ("tcp" , "127.0.0.1:" )
99
+ if err != nil {
100
+ t .Fatalf ("failed to listen on 127.0.0.1: %s" , err )
101
+ }
102
+ _ , port , _ := net .SplitHostPort (l .Addr ().String ())
103
+ go func () { http .Serve (l , nil ) }()
97
104
98
105
// Create a local file database.
99
106
localDBName , err := localDB (t )
@@ -110,11 +117,11 @@ func TestClient(t *testing.T) {
110
117
summaries map [string ]string
111
118
}{
112
119
// Test the http client without any cache.
113
- {name : "http-no-cache" , source : "http://localhost:8080" , createCache : func () Cache { return nil }, noVulns : 2 , summaries : map [string ]string {"ID1" : "" , "ID2" : "" }},
120
+ {name : "http-no-cache" , source : "http://localhost:" + port , createCache : func () Cache { return nil }, noVulns : 2 , summaries : map [string ]string {"ID1" : "" , "ID2" : "" }},
114
121
// Test the http client with empty cache.
115
- {name : "http-empty-cache" , source : "http://localhost:8080" , createCache : func () Cache { return & fsCache {} }, noVulns : 2 , summaries : map [string ]string {"ID1" : "" , "ID2" : "" }},
122
+ {name : "http-empty-cache" , source : "http://localhost:" + port , createCache : func () Cache { return & fsCache {} }, noVulns : 2 , summaries : map [string ]string {"ID1" : "" , "ID2" : "" }},
116
123
// Test the client with non-stale cache containing a version of testVuln2 where Summary="cached".
117
- {name : "http-cache" , source : "http://localhost:8080" , createCache : cachedTestVuln2 ("localhost" ), noVulns : 2 , summaries : map [string ]string {"ID1" : "" , "ID2" : "cached" }},
124
+ {name : "http-cache" , source : "http://localhost:" + port , createCache : cachedTestVuln2 ("localhost" ), noVulns : 2 , summaries : map [string ]string {"ID1" : "" , "ID2" : "cached" }},
118
125
// Repeat the same for local file client.
119
126
{name : "file-no-cache" , source : "file://" + localDBName , createCache : func () Cache { return nil }, noVulns : 2 , summaries : map [string ]string {"ID1" : "" , "ID2" : "" }},
120
127
{name : "file-empty-cache" , source : "file://" + localDBName , createCache : func () Cache { return & fsCache {} }, noVulns : 2 , summaries : map [string ]string {"ID1" : "" , "ID2" : "" }},
0 commit comments