Пример #1
0
func TestRedisReadFromClosed(t *testing.T) {
	r, w := newReaderWriter()
	p := make([]byte, 10)

	r.Read(p)
	w.Write([]byte("hello"))
	w.Close()

	// this read should short circuit with EOF
	_, err := r.Read(p)
	assert.Equal(t, err, io.EOF)

	// We'll get true here because r.closed is already set
	assert.True(t, ReaderDone(r))

	// We should still get true here because doneId is set
	r, _ = NewReader(string(r.(*reader).channel))
	assert.True(t, ReaderDone(r))

	// Reader done on a regular io.Reader should return false
	// and not panic
	assert.False(t, ReaderDone(strings.NewReader("hello")))

	// NoContent should respond accordingly based on offset
	assert.False(t, NoContent(r, 0))
	assert.True(t, NoContent(r, 5))
}
Пример #2
0
func TestPut(t *testing.T) {
	server := httptest.NewServer(app())
	defer server.Close()

	transport := &http.Transport{}
	client := &http.Client{Transport: transport}

	// uuid = curl -XPUT <url>/streams/1/2/3
	request, _ := http.NewRequest("PUT", server.URL+"/streams/1/2/3", nil)
	resp, err := client.Do(request)
	defer resp.Body.Close()
	assert.Nil(t, err)
	assert.Equal(t, resp.StatusCode, http.StatusCreated)

	registrar := broker.NewRedisRegistrar()
	assert.True(t, registrar.IsRegistered("1/2/3"))
}