Skip to content

Commit

Permalink
fix server_test to clear TestCacheIndexHandler (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
u5surf authored and cristaloleg committed Jan 16, 2019
1 parent f3acb35 commit 84a0ff3
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,26 +223,27 @@ func TestGetStatsIndex(t *testing.T) {
}

func TestCacheIndexHandler(t *testing.T) {
getreq := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/getKey", nil)
putreq := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/putKey", bytes.NewBuffer([]byte("123")))
delreq := httptest.NewRequest("DELETE", testBaseString+"/api/v1/cache/testDeleteKey", bytes.NewBuffer([]byte("123")))
getreq := httptest.NewRequest("GET", testBaseString+"/api/v1/cache/testkey", nil)
putreq := httptest.NewRequest("PUT", testBaseString+"/api/v1/cache/testkey", bytes.NewBuffer([]byte("123")))
delreq := httptest.NewRequest("DELETE", testBaseString+"/api/v1/cache/testkey", bytes.NewBuffer([]byte("123")))

rr := httptest.NewRecorder()
getrr := httptest.NewRecorder()
putrr := httptest.NewRecorder()
delrr := httptest.NewRecorder()
testHandlers := cacheIndexHandler()

testHandlers.ServeHTTP(rr, putreq)
resp := rr.Result()
if resp.StatusCode != 200 {
t.Errorf("want: 200; got: %d.\n\tcan't delete keys.", resp.StatusCode)
testHandlers.ServeHTTP(putrr, putreq)
resp := putrr.Result()
if resp.StatusCode != 201 {
t.Errorf("want: 201; got: %d.\n\tcan't put keys.", resp.StatusCode)
}
testHandlers.ServeHTTP(rr, getreq)
resp = rr.Result()
testHandlers.ServeHTTP(getrr, getreq)
resp = getrr.Result()
if resp.StatusCode != 200 {
t.Errorf("want: 200; got: %d.\n\tcan't delete keys.", resp.StatusCode)
t.Errorf("want: 200; got: %d.\n\tcan't get keys.", resp.StatusCode)
}

testHandlers.ServeHTTP(rr, delreq)
resp = rr.Result()
testHandlers.ServeHTTP(delrr, delreq)
resp = delrr.Result()
if resp.StatusCode != 200 {
t.Errorf("want: 200; got: %d.\n\tcan't delete keys.", resp.StatusCode)
}
Expand Down

0 comments on commit 84a0ff3

Please sign in to comment.