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