Ejemplo n.º 1
0
func TestGetAllLBs(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Get", "http://localhost/v2/sharedLoadBalancers/test/dc1", mock.Anything).Return(nil)
	service := lb.New(client)

	resp, err := service.GetAll("dc1")

	assert.Nil(err)
	assert.Equal(1, len(resp))
	client.AssertExpectations(t)
}
Ejemplo n.º 2
0
func TestDeleteLB(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Delete", "http://localhost/v2/sharedLoadBalancers/test/dc1/12345", mock.Anything).Return(nil)
	service := lb.New(client)

	id := "12345"
	err := service.Delete("dc1", id)

	assert.Nil(err)
	client.AssertExpectations(t)
}
Ejemplo n.º 3
0
func TestGetLBPool(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Get", "http://localhost/v2/sharedLoadBalancers/test/dc1/12345/pools/56789", mock.Anything).Return(nil)
	service := lb.New(client)

	id := "56789"
	resp, err := service.GetPool("dc1", "12345", id)

	assert.Nil(err)
	assert.Equal(id, resp.ID)
	client.AssertExpectations(t)
}
Ejemplo n.º 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
}
Ejemplo n.º 5
0
func TestUpdateLB(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Put", "http://localhost/v2/sharedLoadBalancers/test/dc1/12345", mock.Anything, nil).Return(nil)
	service := lb.New(client)

	lb := lb.LoadBalancer{
		Name:        "new",
		Description: "balancing load",
	}
	err := service.Update("dc1", "12345", lb)

	assert.Nil(err)
	client.AssertExpectations(t)
}
Ejemplo n.º 6
0
func TestUpdateNodes(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Put", "http://localhost/v2/sharedLoadBalancers/test/dc1/12345/pools/56789/nodes", mock.Anything, nil).Return(nil)
	service := lb.New(client)

	node := lb.Node{
		IPaddress:   "10.0.0.0",
		PrivatePort: 8080,
	}
	err := service.UpdateNodes("dc1", "12345", "56789", node)

	assert.Nil(err)
	client.AssertExpectations(t)
}
Ejemplo n.º 7
0
func TestUpdatePool(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Put", "http://localhost/v2/sharedLoadBalancers/test/dc1/12345/pools/56789", mock.Anything, nil).Return(nil)
	service := lb.New(client)

	pool := lb.Pool{
		Method:      lb.LeastConn,
		Persistence: lb.Sticky,
	}
	err := service.UpdatePool("dc1", "12345", "56789", pool)

	assert.Nil(err)
	client.AssertExpectations(t)
}
Ejemplo n.º 8
0
func TestCreateLB(t *testing.T) {
	assert := assert.New(t)

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

	lb := lb.LoadBalancer{
		Name:        "new",
		Description: "balancing load",
	}
	resp, err := service.Create("dc1", lb)

	assert.Nil(err)
	assert.Equal(lb.Name, resp.Name)
	assert.Equal("enabled", resp.Status)
	assert.NotEmpty(resp.ID)
	client.AssertExpectations(t)
}
Ejemplo n.º 9
0
func TestCreateLBPool(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Post", "http://localhost/v2/sharedLoadBalancers/test/dc1/12345/pools", mock.Anything, mock.Anything).Return(nil)
	service := lb.New(client)

	pool := lb.Pool{
		Port:        80,
		Method:      lb.LeastConn,
		Persistence: lb.Sticky,
	}

	resp, err := service.CreatePool("dc1", "12345", pool)

	assert.Nil(err)
	assert.Equal(pool.Port, resp.Port)
	assert.NotEmpty(resp.ID)
	client.AssertExpectations(t)
}