示例#1
0
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)

}
示例#2
0
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")
}
示例#3
0
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)
}
示例#4
0
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)
}
示例#5
0
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)
}
示例#6
0
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)
}
示例#7
0
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)

}
示例#8
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)
}
示例#9
0
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")
}
示例#10
0
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)
}
示例#11
0
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)
}
示例#12
0
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)
}