Skip to content

Commit bb53d3d

Browse files
authored
maint: prune dead code and tidy up (#387)
With the refactors and migrations going on there was some dead code left behind, some code that could be easily be replaced by generics, and some test code that was doing things differently than the more recent stuff. There's likely more to do in this vein, but this was a bit of a time-boxed effort.
1 parent 04ffa24 commit bb53d3d

20 files changed

+142
-341
lines changed

client/column.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ const (
7676

7777
// ColumnTypes returns an exhaustive list of column types.
7878
func ColumnTypes() []ColumnType {
79-
return []ColumnType{ColumnTypeString, ColumnTypeFloat, ColumnTypeInteger, ColumnTypeBoolean}
79+
return []ColumnType{
80+
ColumnTypeString,
81+
ColumnTypeFloat,
82+
ColumnTypeInteger,
83+
ColumnTypeBoolean,
84+
}
8085
}
8186

8287
func (s *columns) List(ctx context.Context, dataset string) ([]Column, error) {

client/query_spec.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,14 @@ func (c CalculationOp) IsUnaryOp() bool {
167167
return c == CalculationOpCount || c == CalculationOpConcurrency
168168
}
169169

170-
// CalculationOps returns an exhaustive list of calculation operators.
170+
// CalculationOps returns an exhaustive list of Calculation Operators.
171171
func CalculationOps() []CalculationOp {
172+
return append(HavingCalculationOps(), CalculationOpHeatmap)
173+
}
174+
175+
// HavingCalculationOps returns an exhaustive list of calculation operators
176+
// supported by Havings. Havings does not support Heatmap.
177+
func HavingCalculationOps() []CalculationOp {
172178
return []CalculationOp{
173179
CalculationOpCount,
174180
CalculationOpConcurrency,
@@ -188,7 +194,6 @@ func CalculationOps() []CalculationOp {
188194
CalculationOpP95,
189195
CalculationOpP99,
190196
CalculationOpP999,
191-
CalculationOpHeatmap,
192197
CalculationOpRateAvg,
193198
CalculationOpRateSum,
194199
CalculationOpRateMax,

client/type_helpers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package client
22

33
import (
44
"testing"
5+
6+
"github.com/stretchr/testify/assert"
57
)
68

79
func TestEquivalent(t *testing.T) {
@@ -24,9 +26,7 @@ func TestEquivalent(t *testing.T) {
2426
}
2527
for _, tt := range tests {
2628
t.Run(tt.name, func(t *testing.T) {
27-
if got := Equivalent(tt.a, tt.b); got != tt.want {
28-
t.Errorf("Equivalent() = %v, want %v", got, tt.want)
29-
}
29+
assert.Equal(t, tt.want, Equivalent(tt.a, tt.b))
3030
})
3131
}
3232
}

honeycombio/data_source_column_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"strings"
88
"testing"
99

10+
"github.com/stretchr/testify/require"
11+
1012
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1113
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1214

@@ -28,12 +30,12 @@ func TestAccDataSourceHoneycombioColumn_basic(t *testing.T) {
2830

2931
for i, column := range testColumns {
3032
col, err := c.Columns.Create(ctx, dataset, &column)
33+
require.NoError(t, err)
3134
// update ID for removal later
3235
testColumns[i].ID = col.ID
33-
if err != nil {
34-
t.Error(err)
35-
}
36+
3637
}
38+
//nolint:errcheck
3739
t.Cleanup(func() {
3840
// remove Columns at the of the test run
3941
for _, col := range testColumns {

honeycombio/data_source_columns_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"strings"
77
"testing"
88

9+
"github.com/stretchr/testify/require"
10+
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1012
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1113

@@ -32,12 +34,11 @@ func TestAccDataSourceHoneycombioColumns_basic(t *testing.T) {
3234

3335
for i, column := range testColumns {
3436
col, err := c.Columns.Create(ctx, dataset, &column)
37+
require.NoError(t, err)
3538
// update ID for removal later
3639
testColumns[i].ID = col.ID
37-
if err != nil {
38-
t.Error(err)
39-
}
4040
}
41+
//nolint:errcheck
4142
t.Cleanup(func() {
4243
// remove Columns at the of the test run
4344
for _, col := range testColumns {

honeycombio/data_source_query_specification.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
13+
1314
honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
15+
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper"
1416
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/hashcode"
1517
)
1618

@@ -27,7 +29,7 @@ func dataSourceHoneycombioQuerySpec() *schema.Resource {
2729
"op": {
2830
Type: schema.TypeString,
2931
Required: true,
30-
ValidateFunc: validation.StringInSlice(calculationOpStrings(), false),
32+
ValidateFunc: validation.StringInSlice(helper.AsStringSlice(honeycombio.CalculationOps()), false),
3133
},
3234
"column": {
3335
Type: schema.TypeString,
@@ -48,7 +50,7 @@ func dataSourceHoneycombioQuerySpec() *schema.Resource {
4850
"op": {
4951
Type: schema.TypeString,
5052
Required: true,
51-
ValidateFunc: validation.StringInSlice(filterOpStrings(), false),
53+
ValidateFunc: validation.StringInSlice(helper.AsStringSlice(honeycombio.FilterOps()), false),
5254
},
5355
"value": {
5456
Type: schema.TypeString,
@@ -90,7 +92,7 @@ func dataSourceHoneycombioQuerySpec() *schema.Resource {
9092
"calculate_op": {
9193
Type: schema.TypeString,
9294
Required: true,
93-
ValidateFunc: validation.StringInSlice(havingCalculateOpStrings(), false),
95+
ValidateFunc: validation.StringInSlice(helper.AsStringSlice(honeycombio.HavingCalculationOps()), false),
9496
},
9597
"column": {
9698
Type: schema.TypeString,
@@ -100,7 +102,7 @@ func dataSourceHoneycombioQuerySpec() *schema.Resource {
100102
"op": {
101103
Type: schema.TypeString,
102104
Required: true,
103-
ValidateFunc: validation.StringInSlice(havingOpStrings(), false),
105+
ValidateFunc: validation.StringInSlice(helper.AsStringSlice(honeycombio.HavingOps()), false),
104106
},
105107
"value": {
106108
// API currently assumes this is a number
@@ -131,7 +133,7 @@ func dataSourceHoneycombioQuerySpec() *schema.Resource {
131133
"op": {
132134
Type: schema.TypeString,
133135
Optional: true,
134-
ValidateFunc: validation.StringInSlice(calculationOpStrings(), false),
136+
ValidateFunc: validation.StringInSlice(helper.AsStringSlice(honeycombio.CalculationOps()), false),
135137
},
136138
"column": {
137139
Type: schema.TypeString,
@@ -140,7 +142,7 @@ func dataSourceHoneycombioQuerySpec() *schema.Resource {
140142
"order": {
141143
Type: schema.TypeString,
142144
Optional: true,
143-
ValidateFunc: validation.StringInSlice(sortOrderStrings(), false),
145+
ValidateFunc: validation.StringInSlice(helper.AsStringSlice(honeycombio.SortOrders()), false),
144146
},
145147
},
146148
},

honeycombio/data_source_recipient_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import (
66
"regexp"
77
"testing"
88

9+
"github.com/stretchr/testify/require"
10+
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
12+
1013
honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
1114
)
1215

@@ -72,12 +75,11 @@ func TestAccDataSourceHoneycombioRecipient_basic(t *testing.T) {
7275

7376
for i, r := range testRecipients {
7477
rcpt, err := c.Recipients.Create(ctx, &r)
78+
require.NoError(t, err)
7579
// update ID for removal later
7680
testRecipients[i].ID = rcpt.ID
77-
if err != nil {
78-
t.Error(err)
79-
}
8081
}
82+
//nolint:errcheck
8183
t.Cleanup(func() {
8284
// remove Recipients at the of the test run
8385
for _, r := range testRecipients {

honeycombio/data_source_recipients_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import (
55
"fmt"
66
"testing"
77

8+
"github.com/stretchr/testify/require"
9+
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
912
honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
1013
)
1114

@@ -42,12 +45,11 @@ func TestAccDataSourceHoneycombioRecipients_basic(t *testing.T) {
4245

4346
for i, r := range testRecipients {
4447
rcpt, err := c.Recipients.Create(ctx, &r)
48+
require.NoError(t, err)
4549
// update ID for removal later
4650
testRecipients[i].ID = rcpt.ID
47-
if err != nil {
48-
t.Error(err)
49-
}
5051
}
52+
//nolint:errcheck
5153
t.Cleanup(func() {
5254
// remove Recipients at the of the test run
5355
for _, r := range testRecipients {

honeycombio/data_source_trigger_recipient.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
9+
910
honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
11+
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper"
1012
)
1113

1214
func dataSourceHoneycombioSlackRecipient() *schema.Resource {
@@ -21,7 +23,7 @@ func dataSourceHoneycombioSlackRecipient() *schema.Resource {
2123
"type": {
2224
Type: schema.TypeString,
2325
Required: true,
24-
ValidateFunc: validation.StringInSlice(recipientTypeStrings(honeycombio.TriggerRecipientTypes()), false),
26+
ValidateFunc: validation.StringInSlice(helper.AsStringSlice(honeycombio.TriggerRecipientTypes()), false),
2527
},
2628
"target": {
2729
Type: schema.TypeString,

honeycombio/data_source_trigger_recipient_test.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,46 @@
11
package honeycombio
22

33
import (
4+
"context"
45
"fmt"
56
"regexp"
67
"testing"
78

9+
"github.com/stretchr/testify/require"
10+
811
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
12+
913
honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
1014
)
1115

1216
func TestAccDataSourceHoneycombioTriggerRecipient_basic(t *testing.T) {
17+
ctx := context.Background()
1318
dataset := testAccDataset()
19+
c := testAccClient(t)
1420

15-
_, deleteFn := createTriggerWithRecipient(t, dataset, honeycombio.NotificationRecipient{
16-
Type: honeycombio.RecipientTypeEmail,
17-
Target: "[email protected]",
21+
trigger, err := c.Triggers.Create(ctx, dataset, &honeycombio.Trigger{
22+
Name: "test trigger",
23+
Query: &honeycombio.QuerySpec{
24+
Calculations: []honeycombio.CalculationSpec{
25+
{Op: honeycombio.CalculationOpCount},
26+
},
27+
},
28+
Threshold: &honeycombio.TriggerThreshold{
29+
Op: honeycombio.TriggerThresholdOpGreaterThan,
30+
Value: 100,
31+
},
32+
Recipients: []honeycombio.NotificationRecipient{
33+
{
34+
Type: honeycombio.RecipientTypeEmail,
35+
Target: "[email protected]",
36+
},
37+
},
38+
})
39+
require.NoError(t, err)
40+
//nolint:errcheck
41+
t.Cleanup(func() {
42+
c.Triggers.Delete(ctx, dataset, trigger.ID)
1843
})
19-
defer deleteFn()
2044

2145
resource.Test(t, resource.TestCase{
2246
PreCheck: testAccPreCheck(t),
@@ -41,7 +65,7 @@ func testAccTriggerRecipient(dataset, recipientType, target string) string {
4165
return fmt.Sprintf(`
4266
data "honeycombio_trigger_recipient" "test" {
4367
dataset = "%s"
44-
type = "%s"
45-
target = "%s"
68+
type = "%s"
69+
target = "%s"
4670
}`, dataset, recipientType, target)
4771
}

0 commit comments

Comments
 (0)