Skip to content

Commit

Permalink
config: simplify test code (#6123)
Browse files Browse the repository at this point in the history
Removing unnecessary additional Ptr funcs. This is test code only, I
don't think it requires a changelog entry

Signed-off-by: Alex Boten <[email protected]>
Co-authored-by: Robert Pająk <[email protected]>
  • Loading branch information
codeboten and pellared authored Sep 26, 2024
1 parent 7415e67 commit d3836d6
Showing 1 changed file with 60 additions and 72 deletions.
132 changes: 60 additions & 72 deletions config/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ func TestReader(t *testing.T) {
name: "periodic/console-exporter-with-extra-options",
reader: MetricReader{
Periodic: &PeriodicMetricReader{
Interval: newIntPtr(30_000),
Timeout: newIntPtr(5_000),
Interval: ptr(30_000),
Timeout: ptr(5_000),
Exporter: MetricExporter{
Console: Console{},
},
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestView(t *testing.T) {
name: "selector/invalid_type",
view: View{
Selector: &ViewSelector{
InstrumentType: (*ViewSelectorInstrumentType)(newStringPtr("invalid_type")),
InstrumentType: (*ViewSelectorInstrumentType)(ptr("invalid_type")),
},
},
wantErr: "view_selector: instrument_type: invalid value",
Expand All @@ -538,12 +538,12 @@ func TestView(t *testing.T) {
name: "all selectors match",
view: View{
Selector: &ViewSelector{
InstrumentName: newStringPtr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(newStringPtr("counter")),
Unit: newStringPtr("test_unit"),
MeterName: newStringPtr("test_meter_name"),
MeterVersion: newStringPtr("test_meter_version"),
MeterSchemaUrl: newStringPtr("test_schema_url"),
InstrumentName: ptr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(ptr("counter")),
Unit: ptr("test_unit"),
MeterName: ptr("test_meter_name"),
MeterVersion: ptr("test_meter_version"),
MeterSchemaUrl: ptr("test_schema_url"),
},
},
matchInstrument: &sdkmetric.Instrument{
Expand All @@ -563,12 +563,12 @@ func TestView(t *testing.T) {
name: "all selectors no match name",
view: View{
Selector: &ViewSelector{
InstrumentName: newStringPtr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(newStringPtr("counter")),
Unit: newStringPtr("test_unit"),
MeterName: newStringPtr("test_meter_name"),
MeterVersion: newStringPtr("test_meter_version"),
MeterSchemaUrl: newStringPtr("test_schema_url"),
InstrumentName: ptr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(ptr("counter")),
Unit: ptr("test_unit"),
MeterName: ptr("test_meter_name"),
MeterVersion: ptr("test_meter_version"),
MeterSchemaUrl: ptr("test_schema_url"),
},
},
matchInstrument: &sdkmetric.Instrument{
Expand All @@ -588,12 +588,12 @@ func TestView(t *testing.T) {
name: "all selectors no match unit",
view: View{
Selector: &ViewSelector{
InstrumentName: newStringPtr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(newStringPtr("counter")),
Unit: newStringPtr("test_unit"),
MeterName: newStringPtr("test_meter_name"),
MeterVersion: newStringPtr("test_meter_version"),
MeterSchemaUrl: newStringPtr("test_schema_url"),
InstrumentName: ptr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(ptr("counter")),
Unit: ptr("test_unit"),
MeterName: ptr("test_meter_name"),
MeterVersion: ptr("test_meter_version"),
MeterSchemaUrl: ptr("test_schema_url"),
},
},
matchInstrument: &sdkmetric.Instrument{
Expand All @@ -613,12 +613,12 @@ func TestView(t *testing.T) {
name: "all selectors no match kind",
view: View{
Selector: &ViewSelector{
InstrumentName: newStringPtr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(newStringPtr("histogram")),
Unit: newStringPtr("test_unit"),
MeterName: newStringPtr("test_meter_name"),
MeterVersion: newStringPtr("test_meter_version"),
MeterSchemaUrl: newStringPtr("test_schema_url"),
InstrumentName: ptr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(ptr("histogram")),
Unit: ptr("test_unit"),
MeterName: ptr("test_meter_name"),
MeterVersion: ptr("test_meter_version"),
MeterSchemaUrl: ptr("test_schema_url"),
},
},
matchInstrument: &sdkmetric.Instrument{
Expand All @@ -638,12 +638,12 @@ func TestView(t *testing.T) {
name: "all selectors no match meter name",
view: View{
Selector: &ViewSelector{
InstrumentName: newStringPtr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(newStringPtr("counter")),
Unit: newStringPtr("test_unit"),
MeterName: newStringPtr("test_meter_name"),
MeterVersion: newStringPtr("test_meter_version"),
MeterSchemaUrl: newStringPtr("test_schema_url"),
InstrumentName: ptr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(ptr("counter")),
Unit: ptr("test_unit"),
MeterName: ptr("test_meter_name"),
MeterVersion: ptr("test_meter_version"),
MeterSchemaUrl: ptr("test_schema_url"),
},
},
matchInstrument: &sdkmetric.Instrument{
Expand All @@ -663,12 +663,12 @@ func TestView(t *testing.T) {
name: "all selectors no match meter version",
view: View{
Selector: &ViewSelector{
InstrumentName: newStringPtr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(newStringPtr("counter")),
Unit: newStringPtr("test_unit"),
MeterName: newStringPtr("test_meter_name"),
MeterVersion: newStringPtr("test_meter_version"),
MeterSchemaUrl: newStringPtr("test_schema_url"),
InstrumentName: ptr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(ptr("counter")),
Unit: ptr("test_unit"),
MeterName: ptr("test_meter_name"),
MeterVersion: ptr("test_meter_version"),
MeterSchemaUrl: ptr("test_schema_url"),
},
},
matchInstrument: &sdkmetric.Instrument{
Expand All @@ -688,12 +688,12 @@ func TestView(t *testing.T) {
name: "all selectors no match meter schema url",
view: View{
Selector: &ViewSelector{
InstrumentName: newStringPtr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(newStringPtr("counter")),
Unit: newStringPtr("test_unit"),
MeterName: newStringPtr("test_meter_name"),
MeterVersion: newStringPtr("test_meter_version"),
MeterSchemaUrl: newStringPtr("test_schema_url"),
InstrumentName: ptr("test_name"),
InstrumentType: (*ViewSelectorInstrumentType)(ptr("counter")),
Unit: ptr("test_unit"),
MeterName: ptr("test_meter_name"),
MeterVersion: ptr("test_meter_version"),
MeterSchemaUrl: ptr("test_schema_url"),
},
},
matchInstrument: &sdkmetric.Instrument{
Expand All @@ -713,12 +713,12 @@ func TestView(t *testing.T) {
name: "with stream",
view: View{
Selector: &ViewSelector{
InstrumentName: newStringPtr("test_name"),
Unit: newStringPtr("test_unit"),
InstrumentName: ptr("test_name"),
Unit: ptr("test_unit"),
},
Stream: &ViewStream{
Name: newStringPtr("new_name"),
Description: newStringPtr("new_description"),
Name: ptr("new_name"),
Description: ptr("new_description"),
AttributeKeys: []string{"foo", "bar"},
Aggregation: &ViewStreamAggregation{Sum: make(ViewStreamAggregationSum)},
},
Expand Down Expand Up @@ -768,37 +768,37 @@ func TestInstrumentType(t *testing.T) {
},
{
name: "counter",
instType: (*ViewSelectorInstrumentType)(newStringPtr("counter")),
instType: (*ViewSelectorInstrumentType)(ptr("counter")),
wantKind: sdkmetric.InstrumentKindCounter,
},
{
name: "up_down_counter",
instType: (*ViewSelectorInstrumentType)(newStringPtr("up_down_counter")),
instType: (*ViewSelectorInstrumentType)(ptr("up_down_counter")),
wantKind: sdkmetric.InstrumentKindUpDownCounter,
},
{
name: "histogram",
instType: (*ViewSelectorInstrumentType)(newStringPtr("histogram")),
instType: (*ViewSelectorInstrumentType)(ptr("histogram")),
wantKind: sdkmetric.InstrumentKindHistogram,
},
{
name: "observable_counter",
instType: (*ViewSelectorInstrumentType)(newStringPtr("observable_counter")),
instType: (*ViewSelectorInstrumentType)(ptr("observable_counter")),
wantKind: sdkmetric.InstrumentKindObservableCounter,
},
{
name: "observable_up_down_counter",
instType: (*ViewSelectorInstrumentType)(newStringPtr("observable_up_down_counter")),
instType: (*ViewSelectorInstrumentType)(ptr("observable_up_down_counter")),
wantKind: sdkmetric.InstrumentKindObservableUpDownCounter,
},
{
name: "observable_gauge",
instType: (*ViewSelectorInstrumentType)(newStringPtr("observable_gauge")),
instType: (*ViewSelectorInstrumentType)(ptr("observable_gauge")),
wantKind: sdkmetric.InstrumentKindObservableGauge,
},
{
name: "invalid",
instType: (*ViewSelectorInstrumentType)(newStringPtr("invalid")),
instType: (*ViewSelectorInstrumentType)(ptr("invalid")),
wantErr: errors.New("instrument_type: invalid value"),
},
}
Expand Down Expand Up @@ -846,9 +846,9 @@ func TestAggregation(t *testing.T) {
name: "Base2ExponentialBucketHistogram",
aggregation: &ViewStreamAggregation{
Base2ExponentialBucketHistogram: &ViewStreamAggregationBase2ExponentialBucketHistogram{
MaxSize: newIntPtr(2),
MaxScale: newIntPtr(3),
RecordMinMax: newBoolPtr(true),
MaxSize: ptr(2),
MaxScale: ptr(3),
RecordMinMax: ptr(true),
},
},
wantAggregation: sdkmetric.AggregationBase2ExponentialHistogram{
Expand Down Expand Up @@ -886,7 +886,7 @@ func TestAggregation(t *testing.T) {
aggregation: &ViewStreamAggregation{
ExplicitBucketHistogram: &ViewStreamAggregationExplicitBucketHistogram{
Boundaries: []float64{1, 2, 3},
RecordMinMax: newBoolPtr(true),
RecordMinMax: ptr(true),
},
},
wantAggregation: sdkmetric.AggregationExplicitBucketHistogram{
Expand Down Expand Up @@ -949,15 +949,3 @@ func TestAttributeFilter(t *testing.T) {
})
}
}

func newBoolPtr(b bool) *bool {
return &b
}

func newIntPtr(i int) *int {
return &i
}

func newStringPtr(str string) *string {
return &str
}

0 comments on commit d3836d6

Please sign in to comment.