diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cad84714..4a78cb7a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Fixed - Populate policy_id when importing fleet policies and integrations ([#646](https://github.com/elastic/terraform-provider-elasticstack/pull/646)) +- Fix alerting rule update crash when backend responds with HTTP 4xx. ([#649](https://github.com/elastic/terraform-provider-elasticstack/pull/649)) ## [0.11.3] - 2024-05-16 diff --git a/generated/alerting/api_alerting_mocks.go b/generated/alerting/api_alerting_mocks.go new file mode 100644 index 000000000..6b5c46555 --- /dev/null +++ b/generated/alerting/api_alerting_mocks.go @@ -0,0 +1,807 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ../generated/alerting/api_alerting.go +// +// Generated by this command: +// +// mockgen -destination=../generated/alerting/api_alerting_mocks.go -package=alerting -source ../generated/alerting/api_alerting.go AlertingAPI +// + +// Package alerting is a generated GoMock package. +package alerting + +import ( + context "context" + http "net/http" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockAlertingAPI is a mock of AlertingAPI interface. +type MockAlertingAPI struct { + ctrl *gomock.Controller + recorder *MockAlertingAPIMockRecorder +} + +// MockAlertingAPIMockRecorder is the mock recorder for MockAlertingAPI. +type MockAlertingAPIMockRecorder struct { + mock *MockAlertingAPI +} + +// NewMockAlertingAPI creates a new mock instance. +func NewMockAlertingAPI(ctrl *gomock.Controller) *MockAlertingAPI { + mock := &MockAlertingAPI{ctrl: ctrl} + mock.recorder = &MockAlertingAPIMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAlertingAPI) EXPECT() *MockAlertingAPIMockRecorder { + return m.recorder +} + +// CreateRule mocks base method. +func (m *MockAlertingAPI) CreateRule(ctx context.Context, spaceId, ruleId string) ApiCreateRuleRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateRule", ctx, spaceId, ruleId) + ret0, _ := ret[0].(ApiCreateRuleRequest) + return ret0 +} + +// CreateRule indicates an expected call of CreateRule. +func (mr *MockAlertingAPIMockRecorder) CreateRule(ctx, spaceId, ruleId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateRule", reflect.TypeOf((*MockAlertingAPI)(nil).CreateRule), ctx, spaceId, ruleId) +} + +// CreateRuleExecute mocks base method. +func (m *MockAlertingAPI) CreateRuleExecute(r ApiCreateRuleRequest) (*RuleResponseProperties, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateRuleExecute", r) + ret0, _ := ret[0].(*RuleResponseProperties) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// CreateRuleExecute indicates an expected call of CreateRuleExecute. +func (mr *MockAlertingAPIMockRecorder) CreateRuleExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateRuleExecute", reflect.TypeOf((*MockAlertingAPI)(nil).CreateRuleExecute), r) +} + +// DeleteRule mocks base method. +func (m *MockAlertingAPI) DeleteRule(ctx context.Context, ruleId, spaceId string) ApiDeleteRuleRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteRule", ctx, ruleId, spaceId) + ret0, _ := ret[0].(ApiDeleteRuleRequest) + return ret0 +} + +// DeleteRule indicates an expected call of DeleteRule. +func (mr *MockAlertingAPIMockRecorder) DeleteRule(ctx, ruleId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteRule", reflect.TypeOf((*MockAlertingAPI)(nil).DeleteRule), ctx, ruleId, spaceId) +} + +// DeleteRuleExecute mocks base method. +func (m *MockAlertingAPI) DeleteRuleExecute(r ApiDeleteRuleRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteRuleExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DeleteRuleExecute indicates an expected call of DeleteRuleExecute. +func (mr *MockAlertingAPIMockRecorder) DeleteRuleExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteRuleExecute", reflect.TypeOf((*MockAlertingAPI)(nil).DeleteRuleExecute), r) +} + +// DisableRule mocks base method. +func (m *MockAlertingAPI) DisableRule(ctx context.Context, ruleId, spaceId string) ApiDisableRuleRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DisableRule", ctx, ruleId, spaceId) + ret0, _ := ret[0].(ApiDisableRuleRequest) + return ret0 +} + +// DisableRule indicates an expected call of DisableRule. +func (mr *MockAlertingAPIMockRecorder) DisableRule(ctx, ruleId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DisableRule", reflect.TypeOf((*MockAlertingAPI)(nil).DisableRule), ctx, ruleId, spaceId) +} + +// DisableRuleExecute mocks base method. +func (m *MockAlertingAPI) DisableRuleExecute(r ApiDisableRuleRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DisableRuleExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DisableRuleExecute indicates an expected call of DisableRuleExecute. +func (mr *MockAlertingAPIMockRecorder) DisableRuleExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DisableRuleExecute", reflect.TypeOf((*MockAlertingAPI)(nil).DisableRuleExecute), r) +} + +// EnableRule mocks base method. +func (m *MockAlertingAPI) EnableRule(ctx context.Context, ruleId, spaceId string) ApiEnableRuleRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EnableRule", ctx, ruleId, spaceId) + ret0, _ := ret[0].(ApiEnableRuleRequest) + return ret0 +} + +// EnableRule indicates an expected call of EnableRule. +func (mr *MockAlertingAPIMockRecorder) EnableRule(ctx, ruleId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnableRule", reflect.TypeOf((*MockAlertingAPI)(nil).EnableRule), ctx, ruleId, spaceId) +} + +// EnableRuleExecute mocks base method. +func (m *MockAlertingAPI) EnableRuleExecute(r ApiEnableRuleRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EnableRuleExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// EnableRuleExecute indicates an expected call of EnableRuleExecute. +func (mr *MockAlertingAPIMockRecorder) EnableRuleExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnableRuleExecute", reflect.TypeOf((*MockAlertingAPI)(nil).EnableRuleExecute), r) +} + +// FindRules mocks base method. +func (m *MockAlertingAPI) FindRules(ctx context.Context, spaceId string) ApiFindRulesRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FindRules", ctx, spaceId) + ret0, _ := ret[0].(ApiFindRulesRequest) + return ret0 +} + +// FindRules indicates an expected call of FindRules. +func (mr *MockAlertingAPIMockRecorder) FindRules(ctx, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindRules", reflect.TypeOf((*MockAlertingAPI)(nil).FindRules), ctx, spaceId) +} + +// FindRulesExecute mocks base method. +func (m *MockAlertingAPI) FindRulesExecute(r ApiFindRulesRequest) (*FindRules200Response, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FindRulesExecute", r) + ret0, _ := ret[0].(*FindRules200Response) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// FindRulesExecute indicates an expected call of FindRulesExecute. +func (mr *MockAlertingAPIMockRecorder) FindRulesExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindRulesExecute", reflect.TypeOf((*MockAlertingAPI)(nil).FindRulesExecute), r) +} + +// GetAlertingHealth mocks base method. +func (m *MockAlertingAPI) GetAlertingHealth(ctx context.Context, spaceId string) ApiGetAlertingHealthRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAlertingHealth", ctx, spaceId) + ret0, _ := ret[0].(ApiGetAlertingHealthRequest) + return ret0 +} + +// GetAlertingHealth indicates an expected call of GetAlertingHealth. +func (mr *MockAlertingAPIMockRecorder) GetAlertingHealth(ctx, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAlertingHealth", reflect.TypeOf((*MockAlertingAPI)(nil).GetAlertingHealth), ctx, spaceId) +} + +// GetAlertingHealthExecute mocks base method. +func (m *MockAlertingAPI) GetAlertingHealthExecute(r ApiGetAlertingHealthRequest) (*GetAlertingHealth200Response, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAlertingHealthExecute", r) + ret0, _ := ret[0].(*GetAlertingHealth200Response) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetAlertingHealthExecute indicates an expected call of GetAlertingHealthExecute. +func (mr *MockAlertingAPIMockRecorder) GetAlertingHealthExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAlertingHealthExecute", reflect.TypeOf((*MockAlertingAPI)(nil).GetAlertingHealthExecute), r) +} + +// GetRule mocks base method. +func (m *MockAlertingAPI) GetRule(ctx context.Context, ruleId, spaceId string) ApiGetRuleRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRule", ctx, ruleId, spaceId) + ret0, _ := ret[0].(ApiGetRuleRequest) + return ret0 +} + +// GetRule indicates an expected call of GetRule. +func (mr *MockAlertingAPIMockRecorder) GetRule(ctx, ruleId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRule", reflect.TypeOf((*MockAlertingAPI)(nil).GetRule), ctx, ruleId, spaceId) +} + +// GetRuleExecute mocks base method. +func (m *MockAlertingAPI) GetRuleExecute(r ApiGetRuleRequest) (*RuleResponseProperties, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRuleExecute", r) + ret0, _ := ret[0].(*RuleResponseProperties) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetRuleExecute indicates an expected call of GetRuleExecute. +func (mr *MockAlertingAPIMockRecorder) GetRuleExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRuleExecute", reflect.TypeOf((*MockAlertingAPI)(nil).GetRuleExecute), r) +} + +// GetRuleTypes mocks base method. +func (m *MockAlertingAPI) GetRuleTypes(ctx context.Context, spaceId string) ApiGetRuleTypesRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRuleTypes", ctx, spaceId) + ret0, _ := ret[0].(ApiGetRuleTypesRequest) + return ret0 +} + +// GetRuleTypes indicates an expected call of GetRuleTypes. +func (mr *MockAlertingAPIMockRecorder) GetRuleTypes(ctx, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRuleTypes", reflect.TypeOf((*MockAlertingAPI)(nil).GetRuleTypes), ctx, spaceId) +} + +// GetRuleTypesExecute mocks base method. +func (m *MockAlertingAPI) GetRuleTypesExecute(r ApiGetRuleTypesRequest) ([]GetRuleTypes200ResponseInner, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRuleTypesExecute", r) + ret0, _ := ret[0].([]GetRuleTypes200ResponseInner) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetRuleTypesExecute indicates an expected call of GetRuleTypesExecute. +func (mr *MockAlertingAPIMockRecorder) GetRuleTypesExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRuleTypesExecute", reflect.TypeOf((*MockAlertingAPI)(nil).GetRuleTypesExecute), r) +} + +// LegacyCreateAlert mocks base method. +func (m *MockAlertingAPI) LegacyCreateAlert(ctx context.Context, alertId, spaceId string) ApiLegacyCreateAlertRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyCreateAlert", ctx, alertId, spaceId) + ret0, _ := ret[0].(ApiLegacyCreateAlertRequest) + return ret0 +} + +// LegacyCreateAlert indicates an expected call of LegacyCreateAlert. +func (mr *MockAlertingAPIMockRecorder) LegacyCreateAlert(ctx, alertId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyCreateAlert", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyCreateAlert), ctx, alertId, spaceId) +} + +// LegacyCreateAlertExecute mocks base method. +func (m *MockAlertingAPI) LegacyCreateAlertExecute(r ApiLegacyCreateAlertRequest) (*AlertResponseProperties, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyCreateAlertExecute", r) + ret0, _ := ret[0].(*AlertResponseProperties) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// LegacyCreateAlertExecute indicates an expected call of LegacyCreateAlertExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyCreateAlertExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyCreateAlertExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyCreateAlertExecute), r) +} + +// LegacyDisableAlert mocks base method. +func (m *MockAlertingAPI) LegacyDisableAlert(ctx context.Context, spaceId, alertId string) ApiLegacyDisableAlertRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyDisableAlert", ctx, spaceId, alertId) + ret0, _ := ret[0].(ApiLegacyDisableAlertRequest) + return ret0 +} + +// LegacyDisableAlert indicates an expected call of LegacyDisableAlert. +func (mr *MockAlertingAPIMockRecorder) LegacyDisableAlert(ctx, spaceId, alertId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyDisableAlert", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyDisableAlert), ctx, spaceId, alertId) +} + +// LegacyDisableAlertExecute mocks base method. +func (m *MockAlertingAPI) LegacyDisableAlertExecute(r ApiLegacyDisableAlertRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyDisableAlertExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LegacyDisableAlertExecute indicates an expected call of LegacyDisableAlertExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyDisableAlertExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyDisableAlertExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyDisableAlertExecute), r) +} + +// LegacyEnableAlert mocks base method. +func (m *MockAlertingAPI) LegacyEnableAlert(ctx context.Context, spaceId, alertId string) ApiLegacyEnableAlertRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyEnableAlert", ctx, spaceId, alertId) + ret0, _ := ret[0].(ApiLegacyEnableAlertRequest) + return ret0 +} + +// LegacyEnableAlert indicates an expected call of LegacyEnableAlert. +func (mr *MockAlertingAPIMockRecorder) LegacyEnableAlert(ctx, spaceId, alertId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyEnableAlert", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyEnableAlert), ctx, spaceId, alertId) +} + +// LegacyEnableAlertExecute mocks base method. +func (m *MockAlertingAPI) LegacyEnableAlertExecute(r ApiLegacyEnableAlertRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyEnableAlertExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LegacyEnableAlertExecute indicates an expected call of LegacyEnableAlertExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyEnableAlertExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyEnableAlertExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyEnableAlertExecute), r) +} + +// LegacyFindAlerts mocks base method. +func (m *MockAlertingAPI) LegacyFindAlerts(ctx context.Context, spaceId string) ApiLegacyFindAlertsRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyFindAlerts", ctx, spaceId) + ret0, _ := ret[0].(ApiLegacyFindAlertsRequest) + return ret0 +} + +// LegacyFindAlerts indicates an expected call of LegacyFindAlerts. +func (mr *MockAlertingAPIMockRecorder) LegacyFindAlerts(ctx, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyFindAlerts", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyFindAlerts), ctx, spaceId) +} + +// LegacyFindAlertsExecute mocks base method. +func (m *MockAlertingAPI) LegacyFindAlertsExecute(r ApiLegacyFindAlertsRequest) (*LegacyFindAlerts200Response, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyFindAlertsExecute", r) + ret0, _ := ret[0].(*LegacyFindAlerts200Response) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// LegacyFindAlertsExecute indicates an expected call of LegacyFindAlertsExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyFindAlertsExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyFindAlertsExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyFindAlertsExecute), r) +} + +// LegacyGetAlert mocks base method. +func (m *MockAlertingAPI) LegacyGetAlert(ctx context.Context, spaceId, alertId string) ApiLegacyGetAlertRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyGetAlert", ctx, spaceId, alertId) + ret0, _ := ret[0].(ApiLegacyGetAlertRequest) + return ret0 +} + +// LegacyGetAlert indicates an expected call of LegacyGetAlert. +func (mr *MockAlertingAPIMockRecorder) LegacyGetAlert(ctx, spaceId, alertId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyGetAlert", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyGetAlert), ctx, spaceId, alertId) +} + +// LegacyGetAlertExecute mocks base method. +func (m *MockAlertingAPI) LegacyGetAlertExecute(r ApiLegacyGetAlertRequest) (*AlertResponseProperties, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyGetAlertExecute", r) + ret0, _ := ret[0].(*AlertResponseProperties) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// LegacyGetAlertExecute indicates an expected call of LegacyGetAlertExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyGetAlertExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyGetAlertExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyGetAlertExecute), r) +} + +// LegacyGetAlertTypes mocks base method. +func (m *MockAlertingAPI) LegacyGetAlertTypes(ctx context.Context, spaceId string) ApiLegacyGetAlertTypesRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyGetAlertTypes", ctx, spaceId) + ret0, _ := ret[0].(ApiLegacyGetAlertTypesRequest) + return ret0 +} + +// LegacyGetAlertTypes indicates an expected call of LegacyGetAlertTypes. +func (mr *MockAlertingAPIMockRecorder) LegacyGetAlertTypes(ctx, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyGetAlertTypes", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyGetAlertTypes), ctx, spaceId) +} + +// LegacyGetAlertTypesExecute mocks base method. +func (m *MockAlertingAPI) LegacyGetAlertTypesExecute(r ApiLegacyGetAlertTypesRequest) ([]LegacyGetAlertTypes200ResponseInner, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyGetAlertTypesExecute", r) + ret0, _ := ret[0].([]LegacyGetAlertTypes200ResponseInner) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// LegacyGetAlertTypesExecute indicates an expected call of LegacyGetAlertTypesExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyGetAlertTypesExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyGetAlertTypesExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyGetAlertTypesExecute), r) +} + +// LegacyGetAlertingHealth mocks base method. +func (m *MockAlertingAPI) LegacyGetAlertingHealth(ctx context.Context, spaceId string) ApiLegacyGetAlertingHealthRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyGetAlertingHealth", ctx, spaceId) + ret0, _ := ret[0].(ApiLegacyGetAlertingHealthRequest) + return ret0 +} + +// LegacyGetAlertingHealth indicates an expected call of LegacyGetAlertingHealth. +func (mr *MockAlertingAPIMockRecorder) LegacyGetAlertingHealth(ctx, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyGetAlertingHealth", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyGetAlertingHealth), ctx, spaceId) +} + +// LegacyGetAlertingHealthExecute mocks base method. +func (m *MockAlertingAPI) LegacyGetAlertingHealthExecute(r ApiLegacyGetAlertingHealthRequest) (*LegacyGetAlertingHealth200Response, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyGetAlertingHealthExecute", r) + ret0, _ := ret[0].(*LegacyGetAlertingHealth200Response) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// LegacyGetAlertingHealthExecute indicates an expected call of LegacyGetAlertingHealthExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyGetAlertingHealthExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyGetAlertingHealthExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyGetAlertingHealthExecute), r) +} + +// LegacyMuteAlertInstance mocks base method. +func (m *MockAlertingAPI) LegacyMuteAlertInstance(ctx context.Context, spaceId, alertId, alertInstanceId string) ApiLegacyMuteAlertInstanceRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyMuteAlertInstance", ctx, spaceId, alertId, alertInstanceId) + ret0, _ := ret[0].(ApiLegacyMuteAlertInstanceRequest) + return ret0 +} + +// LegacyMuteAlertInstance indicates an expected call of LegacyMuteAlertInstance. +func (mr *MockAlertingAPIMockRecorder) LegacyMuteAlertInstance(ctx, spaceId, alertId, alertInstanceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyMuteAlertInstance", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyMuteAlertInstance), ctx, spaceId, alertId, alertInstanceId) +} + +// LegacyMuteAlertInstanceExecute mocks base method. +func (m *MockAlertingAPI) LegacyMuteAlertInstanceExecute(r ApiLegacyMuteAlertInstanceRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyMuteAlertInstanceExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LegacyMuteAlertInstanceExecute indicates an expected call of LegacyMuteAlertInstanceExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyMuteAlertInstanceExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyMuteAlertInstanceExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyMuteAlertInstanceExecute), r) +} + +// LegacyMuteAllAlertInstances mocks base method. +func (m *MockAlertingAPI) LegacyMuteAllAlertInstances(ctx context.Context, spaceId, alertId string) ApiLegacyMuteAllAlertInstancesRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyMuteAllAlertInstances", ctx, spaceId, alertId) + ret0, _ := ret[0].(ApiLegacyMuteAllAlertInstancesRequest) + return ret0 +} + +// LegacyMuteAllAlertInstances indicates an expected call of LegacyMuteAllAlertInstances. +func (mr *MockAlertingAPIMockRecorder) LegacyMuteAllAlertInstances(ctx, spaceId, alertId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyMuteAllAlertInstances", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyMuteAllAlertInstances), ctx, spaceId, alertId) +} + +// LegacyMuteAllAlertInstancesExecute mocks base method. +func (m *MockAlertingAPI) LegacyMuteAllAlertInstancesExecute(r ApiLegacyMuteAllAlertInstancesRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyMuteAllAlertInstancesExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LegacyMuteAllAlertInstancesExecute indicates an expected call of LegacyMuteAllAlertInstancesExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyMuteAllAlertInstancesExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyMuteAllAlertInstancesExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyMuteAllAlertInstancesExecute), r) +} + +// LegacyUnmuteAlertInstance mocks base method. +func (m *MockAlertingAPI) LegacyUnmuteAlertInstance(ctx context.Context, spaceId, alertId, alertInstanceId string) ApiLegacyUnmuteAlertInstanceRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyUnmuteAlertInstance", ctx, spaceId, alertId, alertInstanceId) + ret0, _ := ret[0].(ApiLegacyUnmuteAlertInstanceRequest) + return ret0 +} + +// LegacyUnmuteAlertInstance indicates an expected call of LegacyUnmuteAlertInstance. +func (mr *MockAlertingAPIMockRecorder) LegacyUnmuteAlertInstance(ctx, spaceId, alertId, alertInstanceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyUnmuteAlertInstance", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyUnmuteAlertInstance), ctx, spaceId, alertId, alertInstanceId) +} + +// LegacyUnmuteAlertInstanceExecute mocks base method. +func (m *MockAlertingAPI) LegacyUnmuteAlertInstanceExecute(r ApiLegacyUnmuteAlertInstanceRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyUnmuteAlertInstanceExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LegacyUnmuteAlertInstanceExecute indicates an expected call of LegacyUnmuteAlertInstanceExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyUnmuteAlertInstanceExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyUnmuteAlertInstanceExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyUnmuteAlertInstanceExecute), r) +} + +// LegacyUnmuteAllAlertInstances mocks base method. +func (m *MockAlertingAPI) LegacyUnmuteAllAlertInstances(ctx context.Context, spaceId, alertId string) ApiLegacyUnmuteAllAlertInstancesRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyUnmuteAllAlertInstances", ctx, spaceId, alertId) + ret0, _ := ret[0].(ApiLegacyUnmuteAllAlertInstancesRequest) + return ret0 +} + +// LegacyUnmuteAllAlertInstances indicates an expected call of LegacyUnmuteAllAlertInstances. +func (mr *MockAlertingAPIMockRecorder) LegacyUnmuteAllAlertInstances(ctx, spaceId, alertId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyUnmuteAllAlertInstances", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyUnmuteAllAlertInstances), ctx, spaceId, alertId) +} + +// LegacyUnmuteAllAlertInstancesExecute mocks base method. +func (m *MockAlertingAPI) LegacyUnmuteAllAlertInstancesExecute(r ApiLegacyUnmuteAllAlertInstancesRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyUnmuteAllAlertInstancesExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LegacyUnmuteAllAlertInstancesExecute indicates an expected call of LegacyUnmuteAllAlertInstancesExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyUnmuteAllAlertInstancesExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyUnmuteAllAlertInstancesExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyUnmuteAllAlertInstancesExecute), r) +} + +// LegacyUpdateAlert mocks base method. +func (m *MockAlertingAPI) LegacyUpdateAlert(ctx context.Context, spaceId, alertId string) ApiLegacyUpdateAlertRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyUpdateAlert", ctx, spaceId, alertId) + ret0, _ := ret[0].(ApiLegacyUpdateAlertRequest) + return ret0 +} + +// LegacyUpdateAlert indicates an expected call of LegacyUpdateAlert. +func (mr *MockAlertingAPIMockRecorder) LegacyUpdateAlert(ctx, spaceId, alertId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyUpdateAlert", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyUpdateAlert), ctx, spaceId, alertId) +} + +// LegacyUpdateAlertExecute mocks base method. +func (m *MockAlertingAPI) LegacyUpdateAlertExecute(r ApiLegacyUpdateAlertRequest) (*AlertResponseProperties, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyUpdateAlertExecute", r) + ret0, _ := ret[0].(*AlertResponseProperties) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// LegacyUpdateAlertExecute indicates an expected call of LegacyUpdateAlertExecute. +func (mr *MockAlertingAPIMockRecorder) LegacyUpdateAlertExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyUpdateAlertExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegacyUpdateAlertExecute), r) +} + +// LegaryDeleteAlert mocks base method. +func (m *MockAlertingAPI) LegaryDeleteAlert(ctx context.Context, spaceId, alertId string) ApiLegaryDeleteAlertRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegaryDeleteAlert", ctx, spaceId, alertId) + ret0, _ := ret[0].(ApiLegaryDeleteAlertRequest) + return ret0 +} + +// LegaryDeleteAlert indicates an expected call of LegaryDeleteAlert. +func (mr *MockAlertingAPIMockRecorder) LegaryDeleteAlert(ctx, spaceId, alertId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegaryDeleteAlert", reflect.TypeOf((*MockAlertingAPI)(nil).LegaryDeleteAlert), ctx, spaceId, alertId) +} + +// LegaryDeleteAlertExecute mocks base method. +func (m *MockAlertingAPI) LegaryDeleteAlertExecute(r ApiLegaryDeleteAlertRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegaryDeleteAlertExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LegaryDeleteAlertExecute indicates an expected call of LegaryDeleteAlertExecute. +func (mr *MockAlertingAPIMockRecorder) LegaryDeleteAlertExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegaryDeleteAlertExecute", reflect.TypeOf((*MockAlertingAPI)(nil).LegaryDeleteAlertExecute), r) +} + +// MuteAlert mocks base method. +func (m *MockAlertingAPI) MuteAlert(ctx context.Context, alertId, ruleId, spaceId string) ApiMuteAlertRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MuteAlert", ctx, alertId, ruleId, spaceId) + ret0, _ := ret[0].(ApiMuteAlertRequest) + return ret0 +} + +// MuteAlert indicates an expected call of MuteAlert. +func (mr *MockAlertingAPIMockRecorder) MuteAlert(ctx, alertId, ruleId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MuteAlert", reflect.TypeOf((*MockAlertingAPI)(nil).MuteAlert), ctx, alertId, ruleId, spaceId) +} + +// MuteAlertExecute mocks base method. +func (m *MockAlertingAPI) MuteAlertExecute(r ApiMuteAlertRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MuteAlertExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// MuteAlertExecute indicates an expected call of MuteAlertExecute. +func (mr *MockAlertingAPIMockRecorder) MuteAlertExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MuteAlertExecute", reflect.TypeOf((*MockAlertingAPI)(nil).MuteAlertExecute), r) +} + +// MuteAllAlerts mocks base method. +func (m *MockAlertingAPI) MuteAllAlerts(ctx context.Context, ruleId, spaceId string) ApiMuteAllAlertsRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MuteAllAlerts", ctx, ruleId, spaceId) + ret0, _ := ret[0].(ApiMuteAllAlertsRequest) + return ret0 +} + +// MuteAllAlerts indicates an expected call of MuteAllAlerts. +func (mr *MockAlertingAPIMockRecorder) MuteAllAlerts(ctx, ruleId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MuteAllAlerts", reflect.TypeOf((*MockAlertingAPI)(nil).MuteAllAlerts), ctx, ruleId, spaceId) +} + +// MuteAllAlertsExecute mocks base method. +func (m *MockAlertingAPI) MuteAllAlertsExecute(r ApiMuteAllAlertsRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "MuteAllAlertsExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// MuteAllAlertsExecute indicates an expected call of MuteAllAlertsExecute. +func (mr *MockAlertingAPIMockRecorder) MuteAllAlertsExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MuteAllAlertsExecute", reflect.TypeOf((*MockAlertingAPI)(nil).MuteAllAlertsExecute), r) +} + +// UnmuteAlert mocks base method. +func (m *MockAlertingAPI) UnmuteAlert(ctx context.Context, alertId, ruleId, spaceId string) ApiUnmuteAlertRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnmuteAlert", ctx, alertId, ruleId, spaceId) + ret0, _ := ret[0].(ApiUnmuteAlertRequest) + return ret0 +} + +// UnmuteAlert indicates an expected call of UnmuteAlert. +func (mr *MockAlertingAPIMockRecorder) UnmuteAlert(ctx, alertId, ruleId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnmuteAlert", reflect.TypeOf((*MockAlertingAPI)(nil).UnmuteAlert), ctx, alertId, ruleId, spaceId) +} + +// UnmuteAlertExecute mocks base method. +func (m *MockAlertingAPI) UnmuteAlertExecute(r ApiUnmuteAlertRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnmuteAlertExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UnmuteAlertExecute indicates an expected call of UnmuteAlertExecute. +func (mr *MockAlertingAPIMockRecorder) UnmuteAlertExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnmuteAlertExecute", reflect.TypeOf((*MockAlertingAPI)(nil).UnmuteAlertExecute), r) +} + +// UnmuteAllAlerts mocks base method. +func (m *MockAlertingAPI) UnmuteAllAlerts(ctx context.Context, ruleId, spaceId string) ApiUnmuteAllAlertsRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnmuteAllAlerts", ctx, ruleId, spaceId) + ret0, _ := ret[0].(ApiUnmuteAllAlertsRequest) + return ret0 +} + +// UnmuteAllAlerts indicates an expected call of UnmuteAllAlerts. +func (mr *MockAlertingAPIMockRecorder) UnmuteAllAlerts(ctx, ruleId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnmuteAllAlerts", reflect.TypeOf((*MockAlertingAPI)(nil).UnmuteAllAlerts), ctx, ruleId, spaceId) +} + +// UnmuteAllAlertsExecute mocks base method. +func (m *MockAlertingAPI) UnmuteAllAlertsExecute(r ApiUnmuteAllAlertsRequest) (*http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnmuteAllAlertsExecute", r) + ret0, _ := ret[0].(*http.Response) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UnmuteAllAlertsExecute indicates an expected call of UnmuteAllAlertsExecute. +func (mr *MockAlertingAPIMockRecorder) UnmuteAllAlertsExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnmuteAllAlertsExecute", reflect.TypeOf((*MockAlertingAPI)(nil).UnmuteAllAlertsExecute), r) +} + +// UpdateRule mocks base method. +func (m *MockAlertingAPI) UpdateRule(ctx context.Context, ruleId, spaceId string) ApiUpdateRuleRequest { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateRule", ctx, ruleId, spaceId) + ret0, _ := ret[0].(ApiUpdateRuleRequest) + return ret0 +} + +// UpdateRule indicates an expected call of UpdateRule. +func (mr *MockAlertingAPIMockRecorder) UpdateRule(ctx, ruleId, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRule", reflect.TypeOf((*MockAlertingAPI)(nil).UpdateRule), ctx, ruleId, spaceId) +} + +// UpdateRuleExecute mocks base method. +func (m *MockAlertingAPI) UpdateRuleExecute(r ApiUpdateRuleRequest) (*RuleResponseProperties, *http.Response, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateRuleExecute", r) + ret0, _ := ret[0].(*RuleResponseProperties) + ret1, _ := ret[1].(*http.Response) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// UpdateRuleExecute indicates an expected call of UpdateRuleExecute. +func (mr *MockAlertingAPIMockRecorder) UpdateRuleExecute(r any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRuleExecute", reflect.TypeOf((*MockAlertingAPI)(nil).UpdateRuleExecute), r) +} diff --git a/generated/connectors/connectors.gen.go b/generated/connectors/connectors.gen.go index 600b88067..c60db1be8 100644 --- a/generated/connectors/connectors.gen.go +++ b/generated/connectors/connectors.gen.go @@ -1,6 +1,6 @@ // Package connectors provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.0.0 DO NOT EDIT. +// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.1.0 DO NOT EDIT. package connectors import ( @@ -2418,7 +2418,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesCasesWebho return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2446,7 +2446,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesEmail(v Co return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2474,7 +2474,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesIndex(v Co return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2502,7 +2502,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesJira(v Con return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2530,7 +2530,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesOpsgenie(v return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2558,7 +2558,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesPagerduty( return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2586,7 +2586,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesResilient( return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2614,7 +2614,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesServerlog( return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2642,7 +2642,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesServicenow return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2670,7 +2670,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesServicenow return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2698,7 +2698,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesServicenow return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2726,7 +2726,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesSlack(v Co return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2754,7 +2754,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesSlackApi(v return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2782,7 +2782,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesSwimlane(v return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2810,7 +2810,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesTeams(v Co return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2838,7 +2838,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesTines(v Co return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2866,7 +2866,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesWebhook(v return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2894,7 +2894,7 @@ func (t *ConnectorResponseProperties) MergeConnectorResponsePropertiesXmatters(v return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -2985,7 +2985,7 @@ func (t *LegacyRunConnectorGeneralResponse_Data) MergeLegacyRunConnectorGeneralR return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -3011,7 +3011,7 @@ func (t *LegacyRunConnectorGeneralResponse_Data) MergeLegacyRunConnectorGeneralR return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -3047,7 +3047,7 @@ func (t *RunConnectorGeneralResponse_Data) MergeRunConnectorGeneralResponseData0 return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -3073,7 +3073,7 @@ func (t *RunConnectorGeneralResponse_Data) MergeRunConnectorGeneralResponseData1 return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -3109,7 +3109,7 @@ func (t *RunConnectorSubactionPushtoservice_SubActionParams_Incident_DestIp) Mer return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -3135,7 +3135,7 @@ func (t *RunConnectorSubactionPushtoservice_SubActionParams_Incident_DestIp) Mer return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -3171,7 +3171,7 @@ func (t *RunConnectorSubactionPushtoservice_SubActionParams_Incident_MalwareHash return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -3197,7 +3197,7 @@ func (t *RunConnectorSubactionPushtoservice_SubActionParams_Incident_MalwareHash return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -3233,7 +3233,7 @@ func (t *RunConnectorSubactionPushtoservice_SubActionParams_Incident_SourceIp) M return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -3259,7 +3259,7 @@ func (t *RunConnectorSubactionPushtoservice_SubActionParams_Incident_SourceIp) M return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } diff --git a/generated/fleet/fleet.gen.go b/generated/fleet/fleet.gen.go index 1f4685dd4..990ba1b7b 100644 --- a/generated/fleet/fleet.gen.go +++ b/generated/fleet/fleet.gen.go @@ -1,6 +1,6 @@ // Package fleet provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.0.0 DO NOT EDIT. +// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.1.0 DO NOT EDIT. package fleet import ( @@ -961,7 +961,7 @@ func (t *OutputCreateRequest) MergeOutputCreateRequestElasticsearch(v OutputCrea return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -989,7 +989,7 @@ func (t *OutputCreateRequest) MergeOutputCreateRequestKafka(v OutputCreateReques return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -1017,7 +1017,7 @@ func (t *OutputCreateRequest) MergeOutputCreateRequestLogstash(v OutputCreateReq return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -1080,7 +1080,7 @@ func (t *OutputUpdateRequest) MergeOutputUpdateRequestElasticsearch(v OutputUpda return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -1108,7 +1108,7 @@ func (t *OutputUpdateRequest) MergeOutputUpdateRequestKafka(v OutputUpdateReques return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -1136,7 +1136,7 @@ func (t *OutputUpdateRequest) MergeOutputUpdateRequestLogstash(v OutputUpdateReq return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -1197,7 +1197,7 @@ func (t *PackageItemType) MergeKibanaSavedObjectType(v KibanaSavedObjectType) er return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } @@ -1223,7 +1223,7 @@ func (t *PackageItemType) MergeElasticsearchAssetType(v ElasticsearchAssetType) return err } - merged, err := runtime.JsonMerge(t.union, b) + merged, err := runtime.JSONMerge(t.union, b) t.union = merged return err } diff --git a/go.mod b/go.mod index 4e9bfa9aa..63a897be3 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/oapi-codegen/runtime v1.1.1 github.com/stretchr/testify v1.9.0 + go.uber.org/mock v0.4.0 ) require ( @@ -69,7 +70,7 @@ require ( golang.org/x/net v0.23.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect - golang.org/x/tools v0.13.0 // indirect + golang.org/x/tools v0.17.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/grpc v1.63.2 // indirect diff --git a/go.sum b/go.sum index d641d92c6..a9c5914ff 100644 --- a/go.sum +++ b/go.sum @@ -180,6 +180,8 @@ github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8 github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= @@ -230,8 +232,8 @@ golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= +golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= diff --git a/internal/clients/kibana/alerting.go b/internal/clients/kibana/alerting.go index 63d562143..657f218e3 100644 --- a/internal/clients/kibana/alerting.go +++ b/internal/clients/kibana/alerting.go @@ -2,12 +2,14 @@ package kibana import ( "context" + "fmt" "net/http" "github.com/elastic/terraform-provider-elasticstack/generated/alerting" "github.com/elastic/terraform-provider-elasticstack/internal/clients" "github.com/elastic/terraform-provider-elasticstack/internal/models" "github.com/elastic/terraform-provider-elasticstack/internal/utils" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" ) @@ -31,6 +33,7 @@ func ruleResponseToModel(spaceID string, res *alerting.RuleResponseProperties) * Name: res.Name, Consumer: res.Consumer, NotifyWhen: string(unwrapOptionalField(res.NotifyWhen)), + Params: res.Params, RuleTypeID: res.RuleTypeId, Schedule: models.AlertingRuleSchedule{ @@ -62,7 +65,12 @@ func ruleActionsToActionsInner(ruleActions []models.AlertingRuleAction) []alerti return actions } -func CreateAlertingRule(ctx context.Context, apiClient *clients.ApiClient, rule models.AlertingRule) (*models.AlertingRule, diag.Diagnostics) { +type ApiClient interface { + GetAlertingClient() (alerting.AlertingAPI, error) + SetAlertingAuthContext(context.Context) context.Context +} + +func CreateAlertingRule(ctx context.Context, apiClient ApiClient, rule models.AlertingRule) (*models.AlertingRule, diag.Diagnostics) { client, err := apiClient.GetAlertingClient() if err != nil { return nil, diag.FromErr(err) @@ -97,15 +105,27 @@ func CreateAlertingRule(ctx context.Context, apiClient *clients.ApiClient, rule return nil, diag.Errorf("Status code [%d], Saved object [%s/%s] conflict (Rule ID already exists in this Space)", res.StatusCode, rule.SpaceID, rule.RuleID) } - if ruleRes != nil { - rule.RuleID = ruleRes.Id + defer res.Body.Close() + + diags := utils.CheckHttpError(res, "Unabled to create alerting rule") + if diags.HasError() { + return nil, diags } - defer res.Body.Close() - return ruleResponseToModel(rule.SpaceID, ruleRes), utils.CheckHttpError(res, "Unabled to create alerting rule") + if ruleRes == nil { + return nil, diag.Diagnostics{diag.Diagnostic{ + Severity: diag.Error, + Summary: "Create rule returned an empty response", + Detail: fmt.Sprintf("Create rule returned an empty response with HTTP status code [%d].", res.StatusCode), + }} + } + + rule.RuleID = ruleRes.Id + + return ruleResponseToModel(rule.SpaceID, ruleRes), nil } -func UpdateAlertingRule(ctx context.Context, apiClient *clients.ApiClient, rule models.AlertingRule) (*models.AlertingRule, diag.Diagnostics) { +func UpdateAlertingRule(ctx context.Context, apiClient ApiClient, rule models.AlertingRule) (*models.AlertingRule, diag.Diagnostics) { client, err := apiClient.GetAlertingClient() if err != nil { return nil, diag.FromErr(err) @@ -124,18 +144,32 @@ func UpdateAlertingRule(ctx context.Context, apiClient *clients.ApiClient, rule Tags: rule.Tags, Throttle: *alerting.NewNullableString(rule.Throttle), } + req := client.UpdateRule(ctxWithAuth, rule.RuleID, rule.SpaceID).KbnXsrf("true").UpdateRuleRequest(reqModel) + ruleRes, res, err := req.Execute() if err != nil && res == nil { return nil, diag.FromErr(err) } - rule.RuleID = ruleRes.Id + defer res.Body.Close() + if diags := utils.CheckHttpError(res, "Unable to update alerting rule"); diags.HasError() { return nil, diags } + if ruleRes == nil { + return nil, diag.Diagnostics{diag.Diagnostic{ + Severity: diag.Error, + Summary: "Update rule returned an empty response", + Detail: fmt.Sprintf("Update rule returned an empty response with HTTP status code [%d].", res.StatusCode), + }} + } + + rule.RuleID = ruleRes.Id + shouldBeEnabled := rule.Enabled != nil && *rule.Enabled + if shouldBeEnabled && !ruleRes.Enabled { res, err := client.EnableRule(ctxWithAuth, rule.RuleID, rule.SpaceID).KbnXsrf("true").Execute() if err != nil && res == nil { diff --git a/internal/clients/kibana/alerting_mocks.go b/internal/clients/kibana/alerting_mocks.go new file mode 100644 index 000000000..6ec4df61e --- /dev/null +++ b/internal/clients/kibana/alerting_mocks.go @@ -0,0 +1,70 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ../internal/clients/kibana/alerting.go +// +// Generated by this command: +// +// mockgen -destination=../internal/clients/kibana/alerting_mocks.go -package=kibana -source ../internal/clients/kibana/alerting.go ApiClient +// + +// Package kibana is a generated GoMock package. +package kibana + +import ( + context "context" + reflect "reflect" + + alerting "github.com/elastic/terraform-provider-elasticstack/generated/alerting" + gomock "go.uber.org/mock/gomock" +) + +// MockApiClient is a mock of ApiClient interface. +type MockApiClient struct { + ctrl *gomock.Controller + recorder *MockApiClientMockRecorder +} + +// MockApiClientMockRecorder is the mock recorder for MockApiClient. +type MockApiClientMockRecorder struct { + mock *MockApiClient +} + +// NewMockApiClient creates a new mock instance. +func NewMockApiClient(ctrl *gomock.Controller) *MockApiClient { + mock := &MockApiClient{ctrl: ctrl} + mock.recorder = &MockApiClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockApiClient) EXPECT() *MockApiClientMockRecorder { + return m.recorder +} + +// GetAlertingClient mocks base method. +func (m *MockApiClient) GetAlertingClient() (alerting.AlertingAPI, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAlertingClient") + ret0, _ := ret[0].(alerting.AlertingAPI) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAlertingClient indicates an expected call of GetAlertingClient. +func (mr *MockApiClientMockRecorder) GetAlertingClient() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAlertingClient", reflect.TypeOf((*MockApiClient)(nil).GetAlertingClient)) +} + +// SetAlertingAuthContext mocks base method. +func (m *MockApiClient) SetAlertingAuthContext(arg0 context.Context) context.Context { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetAlertingAuthContext", arg0) + ret0, _ := ret[0].(context.Context) + return ret0 +} + +// SetAlertingAuthContext indicates an expected call of SetAlertingAuthContext. +func (mr *MockApiClientMockRecorder) SetAlertingAuthContext(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAlertingAuthContext", reflect.TypeOf((*MockApiClient)(nil).SetAlertingAuthContext), arg0) +} diff --git a/internal/clients/kibana/alerting_test.go b/internal/clients/kibana/alerting_test.go index c5bc8771a..2a9d0b4d2 100644 --- a/internal/clients/kibana/alerting_test.go +++ b/internal/clients/kibana/alerting_test.go @@ -1,12 +1,19 @@ package kibana import ( + "context" + "fmt" + "io" + "net/http" + "strings" "testing" "time" "github.com/elastic/terraform-provider-elasticstack/generated/alerting" "github.com/elastic/terraform-provider-elasticstack/internal/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/stretchr/testify/require" + gomock "go.uber.org/mock/gomock" ) func Test_ruleResponseToModel(t *testing.T) { @@ -122,3 +129,124 @@ func Test_ruleResponseToModel(t *testing.T) { }) } } + +func Test_CreateUpdateAlertingRule(t *testing.T) { + ctrl := gomock.NewController(t) + + getApiClient := func() (ApiClient, *alerting.MockAlertingAPI) { + apiClient := NewMockApiClient(ctrl) + apiClient.EXPECT().SetAlertingAuthContext(gomock.Any()).DoAndReturn(func(ctx context.Context) context.Context { return ctx }) + alertingClient := alerting.NewMockAlertingAPI(ctrl) + apiClient.EXPECT().GetAlertingClient().DoAndReturn(func() (alerting.AlertingAPI, error) { return alertingClient, nil }) + return apiClient, alertingClient + } + + tests := []struct { + name string + testFunc func(ctx context.Context, apiClient ApiClient, rule models.AlertingRule) (*models.AlertingRule, diag.Diagnostics) + client ApiClient + rule models.AlertingRule + expectedRes *models.AlertingRule + expectedErr string + }{ + { + name: "CreateAlertingRule should not crash when backend returns 4xx", + testFunc: CreateAlertingRule, + client: func() ApiClient { + apiClient, alertingClient := getApiClient() + alertingClient.EXPECT().CreateRule(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, spaceId string, ruleId string) alerting.ApiCreateRuleRequest { + return alerting.ApiCreateRuleRequest{ApiService: alertingClient} + }) + alertingClient.EXPECT().CreateRuleExecute(gomock.Any()).DoAndReturn(func(r alerting.ApiCreateRuleRequest) (*alerting.RuleResponseProperties, *http.Response, error) { + return nil, &http.Response{ + StatusCode: 401, + Body: io.NopCloser(strings.NewReader("some error")), + }, nil + }) + return apiClient + }(), + rule: models.AlertingRule{}, + expectedRes: nil, + expectedErr: "some error", + }, + { + name: "UpdateAlertingRule should not crash when backend returns 4xx", + testFunc: UpdateAlertingRule, + client: func() ApiClient { + apiClient, alertingClient := getApiClient() + alertingClient.EXPECT().UpdateRule(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, spaceId string, ruleId string) alerting.ApiUpdateRuleRequest { + return alerting.ApiUpdateRuleRequest{ApiService: alertingClient} + }) + alertingClient.EXPECT().UpdateRuleExecute(gomock.Any()).DoAndReturn(func(r alerting.ApiUpdateRuleRequest) (*alerting.RuleResponseProperties, *http.Response, error) { + return nil, &http.Response{ + StatusCode: 401, + Body: io.NopCloser(strings.NewReader("some error")), + }, nil + }) + return apiClient + }(), + rule: models.AlertingRule{}, + expectedRes: nil, + expectedErr: "some error", + }, + { + name: "CreateAlertingRule should not crash when backend returns an empty response and HTTP 200", + testFunc: CreateAlertingRule, + client: func() ApiClient { + apiClient, alertingClient := getApiClient() + alertingClient.EXPECT().CreateRule(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, spaceId string, ruleId string) alerting.ApiCreateRuleRequest { + return alerting.ApiCreateRuleRequest{ApiService: alertingClient} + }) + alertingClient.EXPECT().CreateRuleExecute(gomock.Any()).DoAndReturn(func(r alerting.ApiCreateRuleRequest) (*alerting.RuleResponseProperties, *http.Response, error) { + return nil, &http.Response{ + StatusCode: 200, + Body: io.NopCloser(strings.NewReader("everything seems fine")), + }, nil + }) + return apiClient + }(), + rule: models.AlertingRule{}, + expectedRes: nil, + expectedErr: "empty response", + }, + { + name: "UpdateAlertingRule should not crash when backend returns an empty response and HTTP 200", + testFunc: UpdateAlertingRule, + client: func() ApiClient { + apiClient, alertingClient := getApiClient() + alertingClient.EXPECT().UpdateRule(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, spaceId string, ruleId string) alerting.ApiUpdateRuleRequest { + return alerting.ApiUpdateRuleRequest{ApiService: alertingClient} + }) + alertingClient.EXPECT().UpdateRuleExecute(gomock.Any()).DoAndReturn(func(r alerting.ApiUpdateRuleRequest) (*alerting.RuleResponseProperties, *http.Response, error) { + return nil, &http.Response{ + StatusCode: 200, + Body: io.NopCloser(strings.NewReader("everything seems fine")), + }, nil + }) + return apiClient + }(), + rule: models.AlertingRule{}, + expectedRes: nil, + expectedErr: "empty response", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + rule, diags := tt.testFunc(context.Background(), tt.client, tt.rule) + + if tt.expectedRes == nil { + require.Nil(t, rule) + } else { + require.Equal(t, tt.expectedRes, rule) + } + + if tt.expectedErr != "" { + require.NotEmpty(t, diags) + if !strings.Contains(diags[0].Detail, tt.expectedErr) { + require.Fail(t, fmt.Sprintf("Diags ['%s'] should contain message ['%s']", diags[0].Detail, tt.expectedErr)) + } + } + }) + } +} diff --git a/tools/connectors_gen.go b/tools/connectors_gen.go index aa9f40c78..a16a4045a 100644 --- a/tools/connectors_gen.go +++ b/tools/connectors_gen.go @@ -1,3 +1,5 @@ //go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -package connectors -o ../generated/connectors/connectors.gen.go -generate "types,client" ../generated/connectors/bundled.yaml +//go:generate go run go.uber.org/mock/mockgen -destination=../generated/alerting/api_alerting_mocks.go -package=alerting -source ../generated/alerting/api_alerting.go AlertingAPI +//go:generate go run go.uber.org/mock/mockgen -destination=../internal/clients/kibana/alerting_mocks.go -package=kibana -source ../internal/clients/kibana/alerting.go ApiClient package tools diff --git a/tools/go.mod b/tools/go.mod index 6f8ca58e7..f0e2dc0a6 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -10,6 +10,7 @@ require ( github.com/golangci/golangci-lint v1.58.2 github.com/goreleaser/goreleaser v1.26.1 github.com/hashicorp/terraform-plugin-docs v0.18.0 + go.uber.org/mock v0.4.0 ) require ( @@ -243,7 +244,7 @@ require ( github.com/hashicorp/terraform-exec v0.20.0 // indirect github.com/hashicorp/terraform-json v0.21.0 // indirect github.com/hexops/gotextdiff v1.0.3 // indirect - github.com/huandu/xstrings v1.3.3 // indirect + github.com/huandu/xstrings v1.4.0 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/invopop/jsonschema v0.12.0 // indirect diff --git a/tools/go.sum b/tools/go.sum index fc2538cf1..a851d48df 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -624,8 +624,9 @@ github.com/hashicorp/terraform-plugin-docs v0.18.0 h1:2bINhzXc+yDeAcafurshCrIjtd github.com/hashicorp/terraform-plugin-docs v0.18.0/go.mod h1:iIUfaJpdUmpi+rI42Kgq+63jAjI8aZVTyxp3Bvk9Hg8= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= -github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= +github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= @@ -1133,6 +1134,8 @@ go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnw go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= diff --git a/tools/tools.go b/tools/tools.go index 6c4ccd488..8f4739a37 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -9,4 +9,5 @@ import ( _ "github.com/golangci/golangci-lint/cmd/golangci-lint" _ "github.com/goreleaser/goreleaser" _ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs" + _ "go.uber.org/mock/mockgen" )