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

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

	a := alert.Alert{
		Name: "new alert",
		Actions: []alert.Action{
			alert.Action{
				Action: "email",
				Setting: alert.Setting{
					Recipients: []string{"*****@*****.**"},
				},
			},
		},
		Triggers: []alert.Trigger{
			alert.Trigger{
				Metric:    "disk",
				Duration:  "00:05:00",
				Threshold: 80.0,
			},
		},
	}
	resp, err := service.Create(a)

	assert.Nil(err)
	assert.Equal(a.Name, resp.Name)
	assert.Equal(a.Actions, resp.Actions)
	assert.Equal(a.Triggers, resp.Triggers)
	client.AssertExpectations(t)
}
Beispiel #2
0
func TestDeleteAlertPolicy(t *testing.T) {
	assert := assert.New(t)

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

	err := service.Delete("12345")

	assert.Nil(err)
	client.AssertExpectations(t)
}
Beispiel #3
0
func TestGetAllAlertPolicies(t *testing.T) {
	assert := assert.New(t)

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

	resp, err := service.GetAll()

	assert.Nil(err)
	assert.Equal(2, len(resp.Items))
}
Beispiel #4
0
func TestGetAlertPolicy(t *testing.T) {
	assert := assert.New(t)

	client := NewMockClient()
	client.On("Get", "http://localhost/v2/alertPolicies/test/12345", mock.Anything).Return(nil)
	service := alert.New(client)

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

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

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

	a := alert.Alert{
		Name: "update alert",
	}
	id := "12345"
	resp, err := service.Update(id, a)

	assert.Nil(err)
	assert.Equal(a.Name, resp.Name)
	assert.Equal("12345", resp.ID)
	client.AssertExpectations(t)
}