Пример #1
0
func (s *ListSuite) Test_Peers_sortsByNameForPresentation(c *g.C) {
	expectedPeers := []*Peer{
		&Peer{
			Jid: "ba", Name: "ab",
		},
		&Peer{
			Jid: "ac", Name: "",
		},
		&Peer{
			Jid: "aa", Name: "bb",
		},
		&Peer{
			Jid: "aa", Name: "cb",
		},
	}

	group := &Group{
		peers: []*Peer{
			expectedPeers[2],
			expectedPeers[0],
			expectedPeers[3],
			expectedPeers[1],
		},
	}

	c.Assert(group.Peers(), g.DeepEquals, expectedPeers)
}
Пример #2
0
func (s *ListSuite) Test_LatestError_setsLatestErrorWhenExists(c *g.C) {
	l := New()
	pp := &Peer{Jid: "*****@*****.**"}
	l.AddOrMerge(pp)
	l.LatestError("[email protected]/foo", "tow", "frou", "sxi")

	c.Assert(pp.LatestError, g.DeepEquals, &PeerError{"tow", "frou", "sxi"})
}
Пример #3
0
func (s *ListSuite) Test_Clear_clearsTheList(c *g.C) {
	l := New()
	l.AddOrMerge(&Peer{Jid: "*****@*****.**"})

	l.Clear()

	c.Assert(len(l.peers), g.Equals, 0)
}
Пример #4
0
func (s *PeerXmppSuite) Test_SetLatestError_setsLatestError(c *g.C) {
	p1 := &Peer{
		Groups:    toSet("one"),
		resources: toSet(),
	}
	p1.SetLatestError("oen", "tow", "there")

	c.Assert(p1.LatestError, g.DeepEquals, &PeerError{"oen", "tow", "there"})
}
Пример #5
0
func (s *PeerXmppSuite) Test_MergeWith_takesTheFirstGroupsIfExists(c *g.C) {
	p1 := &Peer{
		Groups:    toSet("one"),
		resources: toSet(),
	}
	p2 := &Peer{}

	c.Assert(fromSet(p1.MergeWith(p2).Groups)[0], g.Equals, "one")
}
Пример #6
0
func (s *ListSuite) Test_SubscribeRequest_addsTheSubscribeID(c *g.C) {
	l := New()
	l.AddOrMerge(&Peer{Jid: "*****@*****.**"})

	l.SubscribeRequest("[email protected]/hmm", "something", "")
	c.Assert(l.peers["*****@*****.**"].PendingSubscribeID, g.Equals, "something")

	l.SubscribeRequest("[email protected]/hmm2", "something3", "")
	c.Assert(l.peers["*****@*****.**"].PendingSubscribeID, g.Equals, "something3")
}
Пример #7
0
func (s *PeerXmppSuite) Test_Dump_willDumpAllInfo(c *g.C) {
	p := &Peer{
		Jid:          "*****@*****.**",
		Name:         "something",
		Subscription: "from",
		Groups:       toSet("hello::bar"),
		resources:    toSet(),
	}

	c.Assert(p.Dump(), g.Equals, "Peer{[email protected][something ()], subscription='from', status=''('') online=false, asked=false, pendingSubscribe='', belongsTo=''}")
}
Пример #8
0
func assertLogContains(c *gocheck.C, ch <-chan interface{}, exp events.Log) {
	logs := captureLogsEvents(ch)

	for _, l := range logs {
		if reflect.DeepEqual(l, exp) {
			return
		}
	}

	c.Errorf("Could not finr %#v in %#v", exp, logs)
}
Пример #9
0
func (s *ListSuite) Test_ToSlice_createsASliceOfTheContentSortedAlphabetically(c *g.C) {
	l := New()
	l.AddOrMerge(&Peer{Jid: "*****@*****.**"})
	l.AddOrMerge(&Peer{Jid: "*****@*****.**"})
	l.AddOrMerge(&Peer{Jid: "*****@*****.**"})

	c.Assert(l.ToSlice(), g.DeepEquals, []*Peer{
		&Peer{Jid: "*****@*****.**"},
		&Peer{Jid: "*****@*****.**"},
		&Peer{Jid: "*****@*****.**"},
	})
}
Пример #10
0
func (s *GroupListSuite) Test_TopLevelGroup_returnsATopLevelGroup(c *g.C) {
	result := TopLevelGroup()
	c.Check(result.GroupName, g.Equals, "")
	c.Check(result.fullGroupName, g.DeepEquals, []string{})
	c.Check(result.peers, g.DeepEquals, []*Peer{})
	c.Check(result.groups, g.DeepEquals, map[string]*Group{})
}
Пример #11
0
func (s *PeerXmppSuite) Test_PeerWithState_createsANewPeer(c *g.C) {
	p := PeerWithState("[email protected]/1234", "hmm", "no", "", "")
	c.Assert(p.Jid, g.Equals, "*****@*****.**")
	c.Assert(p.Name, g.Equals, "")
	c.Assert(p.Status, g.Equals, "hmm")
	c.Assert(p.StatusMsg, g.Equals, "no")
}
Пример #12
0
func (s *ListSuite) Test_IterAll_willIterateOverAllTheListsGivenAndYieldTheirPeers(c *g.C) {
	l := New()
	l2 := New()
	pp := &Peer{Jid: "*****@*****.**"}
	pp2 := &Peer{Jid: "*****@*****.**"}
	l.AddOrMerge(pp)
	l2.AddOrMerge(pp2)

	result := []*Peer{}
	IterAll(func(_ int, p *Peer) {
		result = append(result, p)
	}, l, l2)

	c.Assert(result, g.DeepEquals, []*Peer{pp2, pp})
}
Пример #13
0
func (s *ListSuite) Test_GetPendingSubscribe_returnsThePendingSubscribeIfExists(c *g.C) {
	l := New()
	l.AddOrMerge(&Peer{Jid: "*****@*****.**", PendingSubscribeID: "foo"})
	l.AddOrMerge(&Peer{Jid: "*****@*****.**"})

	v, k := l.GetPendingSubscribe("*****@*****.**")
	c.Assert(k, g.Equals, false)

	v, k = l.GetPendingSubscribe("[email protected]/bar")
	c.Assert(k, g.Equals, true)
	c.Assert(v, g.Equals, "foo")

	v, k = l.GetPendingSubscribe("[email protected]/bar")
	c.Assert(k, g.Equals, false)
	c.Assert(v, g.Equals, "")
}
Пример #14
0
func (s *ListSuite) Test_Unsubscribed_whenExist(c *g.C) {
	l := New()
	l.AddOrMerge(&Peer{Jid: "*****@*****.**", Subscription: "both", Asked: true, PendingSubscribeID: "foo"})
	l.AddOrMerge(&Peer{Jid: "*****@*****.**", Subscription: "to"})
	l.AddOrMerge(&Peer{Jid: "*****@*****.**", Subscription: "from"})

	l.Unsubscribed("[email protected]/123")
	c.Assert(l.peers["*****@*****.**"].Subscription, g.Equals, "from")
	c.Assert(l.peers["*****@*****.**"].Asked, g.Equals, false)
	c.Assert(l.peers["*****@*****.**"].PendingSubscribeID, g.Equals, "")

	l.Unsubscribed("[email protected]/123")
	c.Assert(l.peers["*****@*****.**"].Subscription, g.Equals, "none")

	l.Unsubscribed("[email protected]/123")
	c.Assert(l.peers["*****@*****.**"].Subscription, g.Equals, "from")
}
Пример #15
0
func (s *PeerXmppSuite) Test_toEntry_ReturnsAnEntryWithTheInformation(c *g.C) {
	p := &Peer{
		Jid:          "*****@*****.**",
		Name:         "something",
		Subscription: "from",
		Groups:       toSet("hello::bar"),
		resources:    toSet(),
	}

	c.Assert(p.ToEntry().Jid, g.Equals, "*****@*****.**")
	c.Assert(p.ToEntry().Name, g.Equals, "something")
	c.Assert(p.ToEntry().Subscription, g.Equals, "from")
	c.Assert(p.ToEntry().Group, g.DeepEquals, []string{"hello::bar"})
}
Пример #16
0
func (s *ListSuite) Test_AddOrMerge_addsTheEntryIfNotInTheList(c *g.C) {
	l := New()
	p := &Peer{Jid: "somewhere", Name: "something"}

	res := l.AddOrMerge(p)

	c.Assert(res, g.Equals, true)
	c.Assert(len(l.peers), g.Equals, 1)
	c.Assert(l.peers["somewhere"], g.Equals, p)
}
Пример #17
0
func (s *ListSuite) Test_Remove_doesNothingWhenAskedToRemoveEntryNotInList(c *g.C) {
	l := New()
	l.peers["*****@*****.**"] = &Peer{}

	res, rem := l.Remove("*****@*****.**")

	c.Assert(rem, g.Equals, false)
	c.Assert(res, g.IsNil)
	c.Assert(len(l.peers), g.Equals, 1)
}
Пример #18
0
func (s *PeerXmppSuite) Test_PeerFrom_returnsANewPeerWithTheSameInformation(c *g.C) {
	re := data.RosterEntry{
		Jid:          "*****@*****.**",
		Subscription: "from",
		Name:         "someone",
		Group: []string{
			"onegroup",
			"twogroup",
		},
	}

	p := PeerFrom(re, "", "", nil)

	c.Assert(p.Jid, g.Equals, "*****@*****.**")
	c.Assert(p.Subscription, g.Equals, "from")
	c.Assert(p.Name, g.Equals, "someone")
	c.Assert(p.Groups, g.DeepEquals, toSet("onegroup", "twogroup"))
}
Пример #19
0
func (s *ListSuite) Test_Remove_removesAnEntryIfInTheList(c *g.C) {
	l := New()
	l.peers["*****@*****.**"] = &Peer{}
	l.peers["*****@*****.**"] = &Peer{Name: "me"}

	res, rem := l.Remove("[email protected]/somewhere")

	c.Assert(rem, g.Equals, true)
	c.Assert(res.Name, g.Equals, "me")
	c.Assert(len(l.peers), g.Equals, 1)
}
Пример #20
0
func (s *ListSuite) Test_PeerBecameUnavailable_setsTheOfflineState(c *g.C) {
	l := New()
	l.AddOrMerge(&Peer{Jid: "*****@*****.**", Online: true})

	res := l.PeerBecameUnavailable("[email protected]/foo")
	c.Assert(res, g.Equals, false)

	res = l.PeerBecameUnavailable("[email protected]/foo2")
	c.Assert(res, g.Equals, true)
	c.Assert(l.peers["*****@*****.**"].Online, g.Equals, false)
}
Пример #21
0
func (s *ListSuite) Test_AddOrReplace_mergesTheEntriesIfInTheList(c *g.C) {
	l := New()
	p1 := &Peer{Jid: "somewhere", Name: "something", Groups: toSet("hello"), Subscription: "from"}
	l.peers["somewhere"] = p1

	p2 := &Peer{Jid: "somewhere", Name: "something2", Groups: toSet("goodbye")}
	res := l.AddOrMerge(p2)

	c.Assert(res, g.Equals, false)
	c.Assert(len(l.peers), g.Equals, 1)
	c.Assert(*l.peers["somewhere"], g.DeepEquals, Peer{Jid: "somewhere", Name: "something2", Groups: toSet("goodbye"), Subscription: "from", resources: toSet()})
}
Пример #22
0
func (s *ListSuite) Test_StateOf_returnsState(c *g.C) {
	l := New()
	l.AddOrMerge(&Peer{Jid: "*****@*****.**", Status: "bla", StatusMsg: "hmm"})

	st, sm, k := l.StateOf("*****@*****.**")
	c.Assert(k, g.Equals, false)

	st, sm, k = l.StateOf("[email protected]/aha")
	c.Assert(k, g.Equals, true)
	c.Assert(st, g.Equals, "bla")
	c.Assert(sm, g.Equals, "hmm")
}
Пример #23
0
func (s *GroupListSuite) Test_Groups_willReturnTheGroups(c *g.C) {
	l := New()
	p1 := &Peer{Jid: "somewhere", Name: "something", Groups: toSet("hello"), Subscription: "from"}
	p2 := &Peer{Jid: "somewhere2", Name: "something2", Groups: toSet("hello", "goodbye::foo::bar"), Subscription: "from"}
	p3 := &Peer{Jid: "somewhere3", Name: "something3", Groups: toSet(), Subscription: "from"}
	l.AddOrMerge(p1)
	l.AddOrMerge(p2)
	l.AddOrMerge(p3)

	gr := l.Grouped("::")
	res := gr.Groups()

	c.Check(len(res), g.Equals, 2)
	c.Check(res[0].FullGroupName(), g.Equals, "goodbye")
	c.Check(res[1].FullGroupName(), g.Equals, "hello")
}
Пример #24
0
func (s *ListSuite) Test_Iter_yieldsEachEntry(c *g.C) {
	l := New()
	l.AddOrMerge(&Peer{Jid: "*****@*****.**"})
	l.AddOrMerge(&Peer{Jid: "*****@*****.**"})
	l.AddOrMerge(&Peer{Jid: "*****@*****.**"})

	called := 0

	l.Iter(func(ix int, p *Peer) {
		called++

		switch ix {
		case 0:
			c.Assert(p, g.DeepEquals, &Peer{Jid: "*****@*****.**"})
		case 1:
			c.Assert(p, g.DeepEquals, &Peer{Jid: "*****@*****.**"})
		case 2:
			c.Assert(p, g.DeepEquals, &Peer{Jid: "*****@*****.**"})
		}
	})

	c.Assert(called, g.DeepEquals, 3)
}
Пример #25
0
func (s *ListSuite) Test_New_returnsANewList(c *g.C) {
	l := New()
	c.Assert(l, g.Not(g.IsNil))
	c.Assert(l.peers, g.Not(g.IsNil))
}
Пример #26
0
func (s *PeerXmppSuite) Test_NameForPresentation_returnsTheNameIfItExistsButJidOtherwise(c *g.C) {
	c.Assert((&Peer{Name: "foo", Jid: "*****@*****.**"}).NameForPresentation(), g.Equals, "foo")
	c.Assert((&Peer{Jid: "*****@*****.**"}).NameForPresentation(), g.Equals, "*****@*****.**")
	c.Assert((&Peer{Jid: "*****@*****.**", Name: "Name", Nickname: "Nick"}).NameForPresentation(), g.Equals, "Nick")
}
Пример #27
0
func (s *PeerXmppSuite) Test_PeerWithPendingSubscribe_createsNewPeer(c *g.C) {
	p := peerWithPendingSubscribe("[email protected]/1234", "223434", "")
	c.Assert(p.Jid, g.Equals, "*****@*****.**")
	c.Assert(p.Name, g.Equals, "")
	c.Assert(p.PendingSubscribeID, g.Equals, "223434")
}
Пример #28
0
func (s *ListSuite) Test_PeerPresenceUpdate_sometimesUpdatesNonExistantPeers(c *g.C) {
	l := New()

	res := l.PeerPresenceUpdate("[email protected]/hmm", "hello", "goodbye", "")
	c.Assert(res, g.Equals, true)
	c.Assert(l.peers["*****@*****.**"].Status, g.Equals, "hello")
	c.Assert(l.peers["*****@*****.**"].StatusMsg, g.Equals, "goodbye")

	res = l.PeerPresenceUpdate("[email protected]/hmm", "xa", "goodbye", "")
	c.Assert(res, g.Equals, false)
	c.Assert(l.peers["*****@*****.**"], g.IsNil)

	res = l.PeerPresenceUpdate("[email protected]/hmm", "away", "goodbye", "")
	c.Assert(res, g.Equals, false)
	c.Assert(l.peers["*****@*****.**"], g.IsNil)

}
Пример #29
0
func (s *ListSuite) Test_PeerPresenceUpdate_updatesPreviouslyKnownPeer(c *g.C) {
	l := New()
	l.AddOrMerge(&Peer{Jid: "*****@*****.**", Online: false, resources: toSet()})
	l.AddOrMerge(&Peer{Jid: "*****@*****.**", Online: true, Status: "dnd", StatusMsg: "working", resources: toSet()})

	res := l.PeerPresenceUpdate("[email protected]/hmm", "hello", "goodbye", "")
	c.Assert(res, g.Equals, true)
	c.Assert(l.peers["*****@*****.**"].Status, g.Equals, "hello")
	c.Assert(l.peers["*****@*****.**"].StatusMsg, g.Equals, "goodbye")
	c.Assert(l.peers["*****@*****.**"].Online, g.Equals, true)

	res = l.PeerPresenceUpdate("[email protected]/hmm", "dnd", "working", "")
	c.Assert(res, g.Equals, false)
	c.Assert(l.peers["*****@*****.**"].Status, g.Equals, "dnd")
	c.Assert(l.peers["*****@*****.**"].StatusMsg, g.Equals, "working")
	c.Assert(l.peers["*****@*****.**"].Online, g.Equals, true)
}
Пример #30
0
func (s *PeerXmppSuite) Test_fromSet_returnsTheKeysInTheSet(c *g.C) {
	c.Assert(fromSet(toSet("helo")), g.DeepEquals, []string{"helo"})
	c.Assert(fromSet(toSet()), g.DeepEquals, []string{})
	c.Assert(len(fromSet(toSet("helo1", "helo2", "helo1"))), g.DeepEquals, 2)
}