address pr comments

This commit is contained in:
Marko Baricevic
2019-09-18 13:42:28 +02:00
parent dd6ba71934
commit 4f5faa5f31
4 changed files with 10 additions and 20 deletions

View File

@@ -352,7 +352,11 @@ func TestSwitchStopPeerForError(t *testing.T) {
defer s.Close()
scrapeMetrics := func() string {
resp, _ := http.Get(s.URL)
resp, err := http.Get(s.URL)
if err != nil {
t.Errorf("error on GET request: %v", err)
}
defer resp.Body.Close()
buf, _ := ioutil.ReadAll(resp.Body)
return string(buf)
}

View File

@@ -70,13 +70,6 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct
if err != nil {
return nil, err
}
// page & perPage === 0 then all validators are returned, no pagination
if page == 0 && perPage == 0 {
return &ctypes.ResultValidators{
BlockHeight: height,
Validators: validators.Validators,
}, nil
}
totalCount := len(validators.Validators)
perPage = validatePerPage(perPage)
@@ -84,23 +77,14 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct
if err != nil {
return nil, err
}
skipCount := validateSkipCount(page, perPage)
apiResults := make([]*types.Validator, cmn.MinInt(perPage, totalCount-skipCount))
for i := 0; i < len(apiResults); i++ {
v := validators.Validators[skipCount+i]
apiResults[i] = &types.Validator{
Address: v.Address,
PubKey: v.PubKey,
VotingPower: v.VotingPower,
ProposerPriority: v.ProposerPriority,
}
}
v := validators.Validators[skipCount : skipCount+cmn.MinInt(perPage, totalCount-skipCount)]
return &ctypes.ResultValidators{
BlockHeight: height,
Validators: apiResults}, nil
Validators: v}, nil
}
// DumpConsensusState dumps consensus state.

View File

@@ -253,6 +253,7 @@ func (c *WSClient) dial() error {
}
rHeader := http.Header{}
conn, _, err := dialer.Dial(c.protocol+"://"+c.Address+c.Endpoint, rHeader)
defer conn.Close()
if err != nil {
return err
}

View File

@@ -70,6 +70,7 @@ func TestRPCParams(t *testing.T) {
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
res := rec.Result()
defer res.Body.Close()
// Always expecting back a JSONRPCResponse
assert.True(t, statusOK(res.StatusCode), "#%d: should always return 2XX", i)
blob, err := ioutil.ReadAll(res.Body)