1
1
package collector
2
2
3
3
import (
4
- "bytes"
5
- "fmt"
6
4
"io"
7
5
"net/http"
8
6
"net/http/httptest"
@@ -18,15 +16,12 @@ func TestClusterSettingsStats(t *testing.T) {
18
16
// docker run -d -p 9200:9200 elasticsearch:VERSION-alpine
19
17
// curl http://localhost:9200/_cluster/settings/?include_defaults=true
20
18
files := []string {"../fixtures/settings-5.4.2.json" , "../fixtures/settings-merge-5.4.2.json" }
21
- buf := bytes .NewBuffer (nil )
22
19
for _ , filename := range files {
23
20
f , _ := os .Open (filename )
24
- io .Copy (buf , f )
25
- f .Close ()
26
- out := string (buf .String ())
21
+ defer f .Close ()
27
22
for hn , handler := range map [string ]http.Handler {
28
23
"plain" : http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
29
- fmt . Fprintln (w , out )
24
+ io . Copy (w , f )
30
25
}),
31
26
} {
32
27
ts := httptest .NewServer (handler )
@@ -57,15 +52,12 @@ func TestClusterMaxShardsPerNode(t *testing.T) {
57
52
// docker run -d -p 9200:9200 elasticsearch:VERSION-alpine
58
53
// curl http://localhost:9200/_cluster/settings/?include_defaults=true
59
54
files := []string {"../fixtures/settings-7.3.0.json" }
60
- buf := bytes .NewBuffer (nil )
61
55
for _ , filename := range files {
62
56
f , _ := os .Open (filename )
63
- io .Copy (buf , f )
64
- f .Close ()
65
- out := string (buf .String ())
57
+ defer f .Close ()
66
58
for hn , handler := range map [string ]http.Handler {
67
59
"plain" : http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
68
- fmt . Fprintln (w , out )
60
+ io . Copy (w , f )
69
61
}),
70
62
} {
71
63
ts := httptest .NewServer (handler )
0 commit comments