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