예제 #1
0
func TestRecordPropogatesNon200Errors(t *testing.T) {
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusBadRequest)
		w.Write([]byte("bad request"))
	}))
	defer server.Close()

	url, _ := url.Parse(server.URL)
	recorder := record.New(url, "1", "bar")

	err := recorder.Record(&StubEvent{Woot: 6})

	assert.Equal(t, "keen: errorful HTTP response: bad request", err.Error())
}
예제 #2
0
func TestRecordMakesSuccessfulRequests(t *testing.T) {
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		payload, err := ioutil.ReadAll(r.Body)

		assert.Nil(t, err)
		assert.Equal(t, "POST", r.Method)
		assert.Equal(t, "/3.0/projects/1/events/foo?api_key=bar", r.URL.String())
		assert.Equal(t, []byte("{\"woot\":6}"), payload)

		w.WriteHeader(http.StatusOK)
	}))
	defer server.Close()

	url, _ := url.Parse(server.URL)
	recorder := record.New(url, "1", "bar")

	err := recorder.Record(&StubEvent{Woot: 6})

	assert.Nil(t, err)
}
예제 #3
0
func TestNewReturnsRecorder(t *testing.T) {
	url, _ := url.Parse("https://api.keen.io/")
	r := record.New(url, "project_id", "write_key")

	assert.IsType(t, &record.KeenRecorder{}, r)
}
예제 #4
0
파일: keen.go 프로젝트: WatchBeam/keen
// Recorder returns a new Recorder used for recording events.
//
// More information can be found in the package github.com/WatchBeam/keen/record
func Recorder(projectId, writeKey string) record.Recorder {
	url, _ := url.Parse("https://api.keen.io/")
	return record.New(url, projectId, writeKey)
}