Skip to content

Commit

Permalink
Merge pull request ipfs/kubo#7550 from trashhalo/dry-up-close
Browse files Browse the repository at this point in the history
use t.Cleanup() to reduce the need to clean up servers in tests

This commit was moved from ipfs/kubo@bd08c0a
  • Loading branch information
aschmahmann authored Aug 25, 2020
2 parents 3ed88d1 + 3937f1f commit 3a9fca1
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions gateway/core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface
// listener, and server with handler. yay cycles.
dh := &delegatedHandler{}
ts := httptest.NewServer(dh)
t.Cleanup(func() { ts.Close() })

dh.Handler, err = makeHandler(n,
ts.Listener,
Expand Down Expand Up @@ -163,7 +164,6 @@ func matchPathOrBreadcrumbs(s string, expected string) bool {
func TestGatewayGet(t *testing.T) {
ns := mockNamesys{}
ts, api, ctx := newTestServerAndNode(t, ns)
defer ts.Close()

k, err := api.Unixfs().Add(ctx, files.NewBytesFile([]byte("fnord")))
if err != nil {
Expand Down Expand Up @@ -244,7 +244,6 @@ func TestGatewayGet(t *testing.T) {
func TestPretty404(t *testing.T) {
ns := mockNamesys{}
ts, api, ctx := newTestServerAndNode(t, ns)
defer ts.Close()

f1 := files.NewMapDirectory(map[string]files.Node{
"ipfs-404.html": files.NewBytesFile([]byte("Custom 404")),
Expand Down Expand Up @@ -309,7 +308,6 @@ func TestIPNSHostnameRedirect(t *testing.T) {
ns := mockNamesys{}
ts, api, ctx := newTestServerAndNode(t, ns)
t.Logf("test server url: %s", ts.URL)
defer ts.Close()

// create /ipns/example.net/foo/index.html

Expand Down Expand Up @@ -397,7 +395,6 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
ns := mockNamesys{}
ts, api, ctx := newTestServerAndNode(t, ns)
t.Logf("test server url: %s", ts.URL)
defer ts.Close()

f1 := files.NewMapDirectory(map[string]files.Node{
"file.txt": files.NewBytesFile([]byte("1")),
Expand Down Expand Up @@ -607,7 +604,6 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
func TestCacheControlImmutable(t *testing.T) {
ts, _, _ := newTestServerAndNode(t, nil)
t.Logf("test server url: %s", ts.URL)
defer ts.Close()

req, err := http.NewRequest(http.MethodGet, ts.URL+emptyDir+"/", nil)
if err != nil {
Expand All @@ -633,7 +629,6 @@ func TestCacheControlImmutable(t *testing.T) {
func TestGoGetSupport(t *testing.T) {
ts, _, _ := newTestServerAndNode(t, nil)
t.Logf("test server url: %s", ts.URL)
defer ts.Close()

// mimic go-get
req, err := http.NewRequest(http.MethodGet, ts.URL+emptyDir+"?go-get=1", nil)
Expand All @@ -657,7 +652,6 @@ func TestVersion(t *testing.T) {
ns := mockNamesys{}
ts, _, _ := newTestServerAndNode(t, ns)
t.Logf("test server url: %s", ts.URL)
defer ts.Close()

req, err := http.NewRequest(http.MethodGet, ts.URL+"/version", nil)
if err != nil {
Expand Down

0 comments on commit 3a9fca1

Please sign in to comment.