use t.Cleanup() to reduce the need to clean up servers
Stephen Solka committed
Jul 18, 2020 at 14:47 UTC
4dbdbe0e029d5af826919376579268da0bc68019
1 file changed
+1
-7
core/corehttp/gateway_test.go
+1
-7
@@ -135,6 +135,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface
135
// listener, and server with handler. yay cycles.
136
dh := &delegatedHandler{}
137
ts := httptest.NewServer(dh)
138
+ t.Cleanup(func() { ts.Close() })
139
140
dh.Handler, err = makeHandler(n,
141
ts.Listener,
@@ -157,7 +158,6 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface
158
func TestGatewayGet(t *testing.T) {
159
ns := mockNamesys{}
160
ts, api, ctx := newTestServerAndNode(t, ns)
160
- defer ts.Close()
161
162
k, err := api.Unixfs().Add(ctx, files.NewBytesFile([]byte("fnord")))
163
if err != nil {
@@ -238,7 +238,6 @@ func TestGatewayGet(t *testing.T) {
238
func TestPretty404(t *testing.T) {
239
ns := mockNamesys{}
240
ts, api, ctx := newTestServerAndNode(t, ns)
241
- defer ts.Close()
241
242
f1 := files.NewMapDirectory(map[string]files.Node{
243
"ipfs-404.html": files.NewBytesFile([]byte("Custom 404")),
@@ -303,7 +302,6 @@ func TestIPNSHostnameRedirect(t *testing.T) {
302
ns := mockNamesys{}
303
ts, api, ctx := newTestServerAndNode(t, ns)
304
t.Logf("test server url: %s", ts.URL)
306
- defer ts.Close()
305
306
// create /ipns/example.net/foo/index.html
307
@@ -391,7 +389,6 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
389
ns := mockNamesys{}
390
ts, api, ctx := newTestServerAndNode(t, ns)
391
t.Logf("test server url: %s", ts.URL)
394
- defer ts.Close()
392
393
f1 := files.NewMapDirectory(map[string]files.Node{
394
"file.txt": files.NewBytesFile([]byte("1")),
@@ -601,7 +598,6 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
598
func TestCacheControlImmutable(t *testing.T) {
599
ts, _, _ := newTestServerAndNode(t, nil)
600
t.Logf("test server url: %s", ts.URL)
604
- defer ts.Close()
601
602
req, err := http.NewRequest(http.MethodGet, ts.URL+emptyDir+"/", nil)
603
if err != nil {
@@ -627,7 +623,6 @@ func TestCacheControlImmutable(t *testing.T) {
623
func TestGoGetSupport(t *testing.T) {
624
ts, _, _ := newTestServerAndNode(t, nil)
625
t.Logf("test server url: %s", ts.URL)
630
- defer ts.Close()
626
627
// mimic go-get
628
req, err := http.NewRequest(http.MethodGet, ts.URL+emptyDir+"?go-get=1", nil)
@@ -651,7 +646,6 @@ func TestVersion(t *testing.T) {
646
ns := mockNamesys{}
647
ts, _, _ := newTestServerAndNode(t, ns)
648
t.Logf("test server url: %s", ts.URL)
654
- defer ts.Close()
649
650
req, err := http.NewRequest(http.MethodGet, ts.URL+"/version", nil)
651
if err != nil {