Skip to content

Commit

Permalink
Add invalid put test that make 500 error in server (#115)
Browse files Browse the repository at this point in the history
* Add invalid put test that make 500 error in server

Signed-off-by: Y.Horie <u5.horie@gmail.com>
  • Loading branch information
u5surf authored and cristaloleg committed Jun 18, 2019
1 parent e24eb22 commit 0605c28
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -248,3 +249,35 @@ func TestCacheIndexHandler(t *testing.T) {
t.Errorf("want: 200; got: %d.\n\tcan't delete keys.", resp.StatusCode)
}
}

func TestInvalidPutWhenExceedShardCap(t *testing.T) {
t.Parallel()
req := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/putKey", bytes.NewBuffer(bytes.Repeat([]byte("a"), 8*1024*1024)))
rr := httptest.NewRecorder()

putCacheHandler(rr, req)
resp := rr.Result()

if resp.StatusCode != 500 {
t.Errorf("want: 500; got: %d", resp.StatusCode)
}
}

func TestInvalidPutWhenReading(t *testing.T) {
t.Parallel()
req := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/putKey", errReader(0))
rr := httptest.NewRecorder()

putCacheHandler(rr, req)
resp := rr.Result()

if resp.StatusCode != 500 {
t.Errorf("want: 500; got: %d", resp.StatusCode)
}
}

type errReader int

func (errReader) Read([]byte) (int, error) {
return 0, errors.New("test read error")
}

0 comments on commit 0605c28

Please sign in to comment.