func TestRemoveAppsMessagesWithMessagesFromOthersRegistered(t *testing.T) {
	setUp()
	a1 := app.NewApp()
	a2 := app.NewApp()
	RecordMsg(a1, "foo")
	RecordMsg(a1, "bar")
	RecordMsg(a2, "baz")
	RecordMsg(a2, "qux")
	RemoveAppsMessages(a1)
	assert.Len(t, appsMessages[a2], 2)
	assert.Equal(t, appsMessages[a2], []string{"baz", "qux"})
	assert.Len(t, msgIdMap, 2)
	assert.Equal(t, msgIdMap["baz"], a2)
}
示例#2
0
// Listens for and accepts a new application connection
// Returns a reference to the App which was accepted
func acceptApp(lnr net.Listener) (*app.App, error) {
	conn, err := lnr.Accept()
	if err != nil {
		return nil, err
	}
	ret := app.NewApp()
	ret.Connection = conn
	return ret, nil
}
func TestRemoveAppsMessagesWithMessagesRegistered(t *testing.T) {
	setUp()
	a := app.NewApp()
	RecordMsg(a, "foo")
	RecordMsg(a, "bar")
	RemoveAppsMessages(a)
	assert.Len(t, appsMessages, 0)
	assert.Len(t, msgIdMap, 0)
}
func TestRecordMsgAppendsAppsMessages(t *testing.T) {
	setUp()
	a := app.NewApp()
	id := "something"
	appsMessages[a] = []string{"something_else"}
	RecordMsg(a, id)

	assert.Len(t, appsMessages[a], 2)
}
func TestRecordMsgCreatesAppsMessagesKey(t *testing.T) {
	setUp()
	a := app.NewApp()
	id := "something"
	RecordMsg(a, id)

	assert.Len(t, appsMessages, 1, "There should be 1 app registered")
	assert.Equal(t, appsMessages[a], []string{id})
}
func TestRecordMsgAddsToMap(t *testing.T) {
	setUp()
	a := app.NewApp()
	id := "something"
	RecordMsg(a, id)

	assert.Len(t, msgIdMap, 1, "The map should have 1 id")
	assert.Equal(t, msgIdMap[id], a, "The map should have some_id -> a")
}
func TestRemoveAppsMessagesWithNothingRegistered(t *testing.T) {
	setUp()
	a := app.NewApp()
	assert.NotPanics(t, func() { RemoveAppsMessages(a) })
}