func TestBrokerRoom(t *testing.T) { broker := NewBroker() room := broker.Room("foo") assert.Equals(t, len(room), 0) messageChan := make(chan *Message) room["SomeGuy"] = messageChan roomWithGuy := broker.Room("foo") assert.Equals(t, len(roomWithGuy), 1) }
func TestStreamBasic(t *testing.T) { response := NewMartiniRecorder() martiniApp := App() // GET and immediately close response.CloseNotifyC <- true request, err := http.NewRequest("GET", "/stream/foo", nil) if err != nil { t.Fail() } martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusOK) assert.Equals(t, response.HeaderMap["Access-Control-Allow-Methods"][0], "POST,OPTIONS") assert.Equals(t, response.HeaderMap["Content-Type"][0], "text/event-stream") }
func TestFailuresMetricaBasic(t *testing.T) { observable := new(TestObservable) m := &FailuresMetrica{observable} val, err := m.GetValue() assert.Equals(t, val, 0.0) assert.Ok(t, err) }
func TestMalformedUpdatePost(t *testing.T) { response := httptest.NewRecorder() martiniApp := App() request, err := http.NewRequest("POST", "/update/foo", strings.NewReader("foo-bar")) if err != nil { t.Fail() } martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusBadRequest) }
func TestMainPage(t *testing.T) { response := httptest.NewRecorder() martiniApp := App() request, err := http.NewRequest("GET", "/", nil) if err != nil { t.Fail() } martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusOK) }
func TestUpdateOptions(t *testing.T) { response := httptest.NewRecorder() martiniApp := App() request, err := http.NewRequest("OPTIONS", "/update/foo", strings.NewReader("")) if err != nil { t.Fail() } martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusOK) }
func TestFailuresStats(t *testing.T) { response := NewMartiniRecorder() martiniApp := App() _, failures := MembersBroker.GetStats() assert.Equals(t, failures, 0) request, err := http.NewRequest("POST", "/failure", nil) assert.Ok(t, err) martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusOK) _, failures = MembersBroker.GetStats() assert.Equals(t, failures, 1) // ensure counter reset _, failures = MembersBroker.GetStats() assert.Equals(t, failures, 0) }
func TestUpdatePostTypeOnly(t *testing.T) { response := httptest.NewRecorder() martiniApp := App() body := []byte(`{"type":"invite", "invite":"invite"}`) request, err := http.NewRequest("POST", "/update/foo", strings.NewReader(string(body))) if err != nil { t.Fail() } martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusOK) }
func TestStreamResponsePayload(t *testing.T) { response := NewMartiniRecorder() martiniApp := App() // GET and immediately close response.CloseNotifyC <- true request, err := http.NewRequest("GET", "/stream/TestStreamResponsePayload", nil) if err != nil { t.Fail() } martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusOK) name, payloads := ParsePayload(response.Body) assert.Equals(t, name, "uid") assert.Equals(t, payloads["type"], "uid") assert.Equals(t, payloads["uid"], payloads["from"]) // present from and to _, ok := payloads["from"] assert.Assert(t, ok, "From field missed") }
func TestUpdatePostNoType(t *testing.T) { response := httptest.NewRecorder() martiniApp := App() body := []byte(`{"from":"c2b0eb25", "to":"bf164412", "invite":"invite"}`) request, err := http.NewRequest("POST", "/update/foo", strings.NewReader(string(body))) if err != nil { t.Fail() } martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusBadRequest) }
func TestUpdatePostNested(t *testing.T) { response := httptest.NewRecorder() martiniApp := App() body := []byte(`{"type":"offer", "from":"c2b0eb25", "to":"bf164412", "offer":{"type":"offer","sdp":"v=0\r\no=Mozilla-SIPUA-28.0 15773 0 IN IP4 0.0.0.0\r\ns"}}`) request, err := http.NewRequest("POST", "/update/foo", strings.NewReader(string(body))) if err != nil { t.Fail() } martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusOK) }
func TestUpdatePostWrongPayloads(t *testing.T) { t.SkipNow() response := httptest.NewRecorder() martiniApp := App() body := []byte(`{"type":"answer", "from":"c2b0eb25", "to":"bf164412", "offer":{"type":"offer","sdp":"v=0\r\no=Mozilla-SIPUA\r\ns"}}`) request, err := http.NewRequest("POST", "/update/foo", strings.NewReader(string(body))) if err != nil { t.Fail() } martiniApp.ServeHTTP(response, request) assert.Equals(t, response.Code, http.StatusBadRequest) }