Skip to content

Commit 856c781

Browse files
TheMeierzwopir
authored andcommitted
use io.Copy in htp handler directly
1 parent 27f2282 commit 856c781

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

collector/cluster_settings_test.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package collector
22

33
import (
4-
"bytes"
5-
"fmt"
64
"io"
75
"net/http"
86
"net/http/httptest"
@@ -18,15 +16,12 @@ func TestClusterSettingsStats(t *testing.T) {
1816
// docker run -d -p 9200:9200 elasticsearch:VERSION-alpine
1917
// curl http://localhost:9200/_cluster/settings/?include_defaults=true
2018
files := []string{"../fixtures/settings-5.4.2.json", "../fixtures/settings-merge-5.4.2.json"}
21-
buf := bytes.NewBuffer(nil)
2219
for _, filename := range files {
2320
f, _ := os.Open(filename)
24-
io.Copy(buf, f)
25-
f.Close()
26-
out := string(buf.String())
21+
defer f.Close()
2722
for hn, handler := range map[string]http.Handler{
2823
"plain": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
29-
fmt.Fprintln(w, out)
24+
io.Copy(w, f)
3025
}),
3126
} {
3227
ts := httptest.NewServer(handler)
@@ -57,15 +52,12 @@ func TestClusterMaxShardsPerNode(t *testing.T) {
5752
// docker run -d -p 9200:9200 elasticsearch:VERSION-alpine
5853
// curl http://localhost:9200/_cluster/settings/?include_defaults=true
5954
files := []string{"../fixtures/settings-7.3.0.json"}
60-
buf := bytes.NewBuffer(nil)
6155
for _, filename := range files {
6256
f, _ := os.Open(filename)
63-
io.Copy(buf, f)
64-
f.Close()
65-
out := string(buf.String())
57+
defer f.Close()
6658
for hn, handler := range map[string]http.Handler{
6759
"plain": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
68-
fmt.Fprintln(w, out)
60+
io.Copy(w, f)
6961
}),
7062
} {
7163
ts := httptest.NewServer(handler)

0 commit comments

Comments
 (0)