Added simple e2e test (POST & GET)

This commit is contained in:
James Mills 2018-05-10 00:54:18 -07:00
rodič f476a2026d
revize 9f01db6002
V databázi nebyl nalezen žádný známý klíč pro tento podpis
ID GPG klíče: AC4C014F1440EBD6

Zobrazit soubor

@ -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")