Skip to content

Commit ca13c73

Browse files
authored
Remove duplicate code (#761)
1 parent 9a6940e commit ca13c73

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

internal/clients/kibana/alerting_test.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/elastic/terraform-provider-elasticstack/generated/alerting"
1313
"github.com/elastic/terraform-provider-elasticstack/internal/models"
14+
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
1415
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1516
"github.com/stretchr/testify/require"
1617
gomock "go.uber.org/mock/gomock"
@@ -49,7 +50,7 @@ func Test_ruleResponseToModel(t *testing.T) {
4950
Consumer: "consumer",
5051
Params: map[string]interface{}{},
5152
RuleTypeID: "rule-type-id",
52-
Enabled: makePtr(true),
53+
Enabled: utils.Pointer(true),
5354
Tags: []string{"hello"},
5455
Actions: []models.AlertingRuleAction{},
5556
},
@@ -65,23 +66,23 @@ func Test_ruleResponseToModel(t *testing.T) {
6566
RuleTypeId: "rule-type-id",
6667
Enabled: true,
6768
Tags: []string{"hello"},
68-
NotifyWhen: *alerting.NewNullableString(makePtr("broken")),
69+
NotifyWhen: *alerting.NewNullableString(utils.Pointer("broken")),
6970
Actions: []alerting.ActionsInner{
7071
{
7172
Group: "group-1",
7273
Id: "id",
7374
Params: map[string]interface{}{},
74-
Frequency: makePtr(alerting.ActionsInnerFrequency{
75+
Frequency: utils.Pointer(alerting.ActionsInnerFrequency{
7576
Summary: true,
7677
NotifyWhen: "onThrottleInterval",
77-
Throttle: *alerting.NewNullableString(makePtr("10s")),
78+
Throttle: *alerting.NewNullableString(utils.Pointer("10s")),
7879
}),
7980
},
8081
{
8182
Group: "group-2",
8283
Id: "id",
8384
Params: map[string]interface{}{},
84-
Frequency: makePtr(alerting.ActionsInnerFrequency{
85+
Frequency: utils.Pointer(alerting.ActionsInnerFrequency{
8586
Summary: true,
8687
NotifyWhen: "onActionGroupChange",
8788
}),
@@ -93,14 +94,14 @@ func Test_ruleResponseToModel(t *testing.T) {
9394
},
9495
},
9596
ExecutionStatus: alerting.RuleResponsePropertiesExecutionStatus{
96-
Status: makePtr("firing"),
97+
Status: utils.Pointer("firing"),
9798
LastExecutionDate: &now,
9899
},
99-
ScheduledTaskId: makePtr("scheduled-task-id"),
100+
ScheduledTaskId: utils.Pointer("scheduled-task-id"),
100101
Schedule: alerting.Schedule{
101-
Interval: makePtr("1m"),
102+
Interval: utils.Pointer("1m"),
102103
},
103-
Throttle: *alerting.NewNullableString(makePtr("throttle")),
104+
Throttle: *alerting.NewNullableString(utils.Pointer("throttle")),
104105
AlertDelay: &alerting.AlertDelay{
105106
Active: float32(4),
106107
},
@@ -112,15 +113,15 @@ func Test_ruleResponseToModel(t *testing.T) {
112113
Consumer: "consumer",
113114
Params: map[string]interface{}{},
114115
RuleTypeID: "rule-type-id",
115-
Enabled: makePtr(true),
116+
Enabled: utils.Pointer(true),
116117
Tags: []string{"hello"},
117-
NotifyWhen: makePtr("broken"),
118+
NotifyWhen: utils.Pointer("broken"),
118119
Schedule: models.AlertingRuleSchedule{Interval: "1m"},
119-
Throttle: makePtr("throttle"),
120-
ScheduledTaskID: makePtr("scheduled-task-id"),
120+
Throttle: utils.Pointer("throttle"),
121+
ScheduledTaskID: utils.Pointer("scheduled-task-id"),
121122
ExecutionStatus: models.AlertingRuleExecutionStatus{
122123
LastExecutionDate: &now,
123-
Status: makePtr("firing"),
124+
Status: utils.Pointer("firing"),
124125
},
125126
Actions: []models.AlertingRuleAction{
126127
{
@@ -130,7 +131,7 @@ func Test_ruleResponseToModel(t *testing.T) {
130131
Frequency: &models.AlertingRuleActionFrequency{
131132
Summary: true,
132133
NotifyWhen: "onThrottleInterval",
133-
Throttle: makePtr("10s"),
134+
Throttle: utils.Pointer("10s"),
134135
},
135136
},
136137
{
@@ -148,7 +149,7 @@ func Test_ruleResponseToModel(t *testing.T) {
148149
Params: map[string]interface{}{},
149150
},
150151
},
151-
AlertDelay: makePtr(float32(4)),
152+
AlertDelay: utils.Pointer(float32(4)),
152153
},
153154
},
154155
}

internal/clients/kibana/common.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,3 @@ func unwrapOptionalField[T any](field *T) T {
88

99
return value
1010
}
11-
12-
func makePtr[T any](v T) *T {
13-
return &v
14-
}

0 commit comments

Comments
 (0)