예제 #1
0
파일: group_test.go 프로젝트: ack/clc-sdk
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)
}
예제 #2
0
파일: group_test.go 프로젝트: ack/clc-sdk
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)
}
예제 #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)
}
예제 #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
}
예제 #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)
}
예제 #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)
}
예제 #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)
}
예제 #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)
}