Added simple e2e test (POST & GET)
This commit is contained in:
rodič
f476a2026d
revize
9f01db6002
|
@ -2,6 +2,7 @@ package msgbus
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
@ -86,6 +87,32 @@ func TestServeHTTPPUT(t *testing.T) {
|
|||
assert.Regexp(`message successfully published to hello with sequence \d+`, w.Body.String())
|
||||
}
|
||||
|
||||
func TestServeHTTPSimple(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
mb := New(nil)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
b := bytes.NewBufferString("hello world")
|
||||
r, _ := http.NewRequest("POST", "/hello", b)
|
||||
|
||||
mb.ServeHTTP(w, r)
|
||||
assert.Equal(w.Code, http.StatusOK)
|
||||
assert.Regexp(`message successfully published to hello with sequence \d+`, w.Body.String())
|
||||
|
||||
w = httptest.NewRecorder()
|
||||
r, _ = http.NewRequest("GET", "/hello", nil)
|
||||
|
||||
mb.ServeHTTP(w, r)
|
||||
assert.Equal(w.Code, http.StatusOK)
|
||||
|
||||
var msg *Message
|
||||
json.Unmarshal(w.Body.Bytes(), &msg)
|
||||
assert.Equal(msg.ID, uint64(0))
|
||||
assert.Equal(msg.Topic.Name, "hello")
|
||||
assert.Equal(msg.Payload, []byte("hello world"))
|
||||
}
|
||||
|
||||
func BenchmarkMessageBusPut(b *testing.B) {
|
||||
mb := New(nil)
|
||||
topic := mb.NewTopic("foo")
|
||||
|
|
Načítá se…
Odkázat v novém úkolu