Example #1
0
	"github.com/twstrike/coyim/Godeps/_workspace/src/github.com/twstrike/gotk3adapter/glib_mock"
	"github.com/twstrike/coyim/i18n"

	g "github.com/twstrike/coyim/Godeps/_workspace/src/gopkg.in/check.v1"
)

func Test(t *testing.T) { g.TestingT(t) }

func init() {
	log.SetOutput(ioutil.Discard)
	i18n.InitLocalization(&glib_mock.Mock{})
}

type ListSuite struct{}

var _ = g.Suite(&ListSuite{})

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))
}

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)
Example #2
0
package roster

import (
	g "github.com/twstrike/coyim/Godeps/_workspace/src/gopkg.in/check.v1"
	"github.com/twstrike/coyim/xmpp/data"
)

type PeerXmppSuite struct{}

var _ = g.Suite(&PeerXmppSuite{})

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

func (s *PeerXmppSuite) Test_fromSet_returnsTheKeysInTheSet(c *g.C) {
Example #3
0
package roster

import g "github.com/twstrike/coyim/Godeps/_workspace/src/gopkg.in/check.v1"

type GroupListSuite struct{}

var _ = g.Suite(&GroupListSuite{})

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{})
}

func (s *GroupListSuite) Test_Grouped_WillGroupPeersInAList(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)

	result := l.Grouped("::")

	c.Check(result.GroupName, g.Equals, "")
	c.Check(result.fullGroupName, g.DeepEquals, []string{})
	c.Check(result.peers, g.DeepEquals, []*Peer{p3})
	c.Check(len(result.groups), g.Equals, 2)