Example #1
0
func TestGetGroup(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Get", "http://localhost/v2/groups/test/67890", mock.Anything).Return(nil)
	service := group.New(client)

	id := "67890"
	resp, err := service.Get(id)

	assert.Nil(err)
	assert.Equal(id, resp.ID)
}
Example #2
0
func TestDeleteGroup(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Delete", "http://localhost/v2/groups/test/67890", mock.Anything).Return(nil)
	service := group.New(client)

	id := "67890"
	resp, err := service.Delete(id)

	assert.Nil(err)
	assert.Equal("status", resp.Rel)
	assert.NotEmpty(resp.ID)
}
Example #3
0
func TestArchiveGroup(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Post", "http://localhost/v2/groups/test/67890/archive", "", mock.Anything).Return(nil)
	service := group.New(client)

	id := "67890"
	resp, err := service.Archive(id)

	assert.Nil(err)
	assert.Equal("status", resp.Rel)
	assert.Equal("wa1-12345", resp.ID)
	client.AssertExpectations(t)
}
Example #4
0
func New(config api.Config) *Client {
	c := &Client{
		client: api.New(config),
	}

	c.Server = server.New(c.client)
	c.Status = status.New(c.client)
	c.AA = aa.New(c.client)
	c.Alert = alert.New(c.client)
	c.LB = lb.New(c.client)
	c.Group = group.New(c.client)
	c.DC = dc.New(c.client)

	return c
}
Example #5
0
func TestGetGroup(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Get", "http://localhost/v2/groups/test/67890", mock.Anything).Return(nil)
	service := group.New(client)

	id := "67890"
	resp, err := service.Get(id)

	assert.Nil(err)
	assert.Equal(id, resp.ID)
	assert.Equal("12345", resp.ParentGroupID())
	assert.Equal(resp.Servers(), []string{})
	client.AssertExpectations(t)
}
Example #6
0
func TestRestoreGroup(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Post", "http://localhost/v2/groups/test/67890/restore", `{"targetGroupId": "55555"}`, mock.Anything).Return(nil)
	service := group.New(client)

	id := "67890"
	resp, err := service.Restore(id, "55555")

	assert.Nil(err)
	ok, qid := resp.GetStatusID()
	assert.True(ok)
	assert.Equal("wa1-12345", qid)
	client.AssertExpectations(t)
}
Example #7
0
func TestUpdateGroup(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Patch", "http://localhost/v2/groups/test/67890", mock.Anything, mock.Anything).Return(nil)
	service := group.New(client)

	id := "67890"
	patches := make([]api.Update, 3)
	patches[0] = group.UpdateName("foobar")
	patches[1] = group.UpdateDescription("mangled")
	patches[2] = group.UpdateParentGroupID("mangled")

	err := service.Update(id, patches...)

	assert.Nil(err)
	client.AssertExpectations(t)
}
Example #8
0
func TestCreateGroup(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Post", "http://localhost/v2/groups/test", mock.Anything, mock.Anything).Return(nil)
	service := group.New(client)

	group := group.Group{
		Name:          "new",
		Description:   "my awesome group",
		ParentGroupID: "12345",
	}
	resp, err := service.Create(group)

	assert.Nil(err)
	assert.Equal(group.Name, resp.Name)
	assert.Equal(1, len(resp.Groups))
	assert.Equal(group.ParentGroupID, resp.ParentGroupID())
	client.AssertExpectations(t)
}