Esempio n. 1
0
func Test_AllKeys_ReturnsData(t *testing.T) {
	dbCalled := false

	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		dbCalled = true
		assert.Equal(t, "/logs/_design/keys/_view/keys", r.URL.Path)
		assert.Equal(t, "group=true", r.URL.RawQuery)

		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, `{"rows":[{"key":"foo","value":1}]}`)
	}))
	defer ts.Close()

	db := couchDb(ts.URL + "/")
	res := db.AllKeys()

	assert.True(t, dbCalled)
	assert.Equal(t, map[string]int{"foo": 1}, res)
}
Esempio n. 2
0
func Test_handlerHandle_SendsReqBody_ToWorkQueue(t *testing.T) {
	jsonInput := map[string]string{
		"message": "hello world",
	}
	body := new(bytes.Buffer)
	json.NewEncoder(body).Encode(jsonInput)
	request, _ := http.NewRequest("POST", "/", body)
	response := httptest.NewRecorder()

	workQueue := make(chan string, 1)
	handler{workQueue: workQueue}.CreateLog(response, request)

	passedBody := <-workQueue

	assert.Equal(t, "{\"message\":\"hello world\"}\n", passedBody)
}