Add tests for getting group(s)

This commit is contained in:
Rob Cutmore 2016-07-16 07:53:56 -04:00
parent b5b0f0ddf8
commit 3a9bc91415

View file

@ -86,6 +86,63 @@ func (s *ModelsSuite) TestPostGroupNoTargets(c *check.C) {
c.Assert(err, check.Equals, ErrNoTargetsSpecified)
}
func (s *ModelsSuite) TestGetGroups(c *check.C) {
// Add groups.
PostGroup(&Group{
Name: "Test Group 1",
Targets: []Target{Target{Email: "test1@example.com"}},
UserId: 1,
})
PostGroup(&Group{
Name: "Test Group 2",
Targets: []Target{Target{Email: "test2@example.com"}},
UserId: 1,
})
// Get groups and test result.
groups, err := GetGroups(1)
c.Assert(err, check.Equals, nil)
c.Assert(len(groups), check.Equals, 2)
c.Assert(len(groups[0].Targets), check.Equals, 1)
c.Assert(len(groups[1].Targets), check.Equals, 1)
c.Assert(groups[0].Name, check.Equals, "Test Group 1")
c.Assert(groups[1].Name, check.Equals, "Test Group 2")
c.Assert(groups[0].Targets[0].Email, check.Equals, "test1@example.com")
c.Assert(groups[1].Targets[0].Email, check.Equals, "test2@example.com")
}
func (s *ModelsSuite) TestGetGroup(c *check.C) {
// Add group.
PostGroup(&Group{
Name: "Test Group",
Targets: []Target{Target{Email: "test@example.com"}},
UserId: 1,
})
// Get group and test result.
group, err := GetGroup(1, 1)
c.Assert(err, check.Equals, nil)
c.Assert(len(group.Targets), check.Equals, 1)
c.Assert(group.Name, check.Equals, "Test Group")
c.Assert(group.Targets[0].Email, check.Equals, "test@example.com")
}
func (s *ModelsSuite) TestGetGroupByName(c *check.C) {
// Add group.
PostGroup(&Group{
Name: "Test Group",
Targets: []Target{Target{Email: "test@example.com"}},
UserId: 1,
})
// Get group and test result.
group, err := GetGroupByName("Test Group", 1)
c.Assert(err, check.Equals, nil)
c.Assert(len(group.Targets), check.Equals, 1)
c.Assert(group.Name, check.Equals, "Test Group")
c.Assert(group.Targets[0].Email, check.Equals, "test@example.com")
}
func (s *ModelsSuite) TestPutGroup(c *check.C) {
// Add test group.
group := Group{Name: "Test Group"}