Skip to content

Commit

Permalink
fill in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Boten <aboten@lightstep.com>
  • Loading branch information
Alex Boten committed Jun 22, 2023
1 parent 79d744c commit 2c8df44
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions service/telemetry/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,58 @@ func TestLoadConfig(t *testing.T) {

func TestUnmarshalMetricReaders(t *testing.T) {
tests := []struct {
name string
cfg *confmap.Conf
success bool
err string
name string
cfg *confmap.Conf
err string
}{
{
name: "invalid config",
cfg: confmap.NewFromStringMap(map[string]any{"invalid": "invalid"}),
err: "unsupported metric reader type: invalid",
},
{
name: "valid reader type, invalid config",
cfg: confmap.NewFromStringMap(map[string]any{"pull": "garbage"}),
err: "invalid pull metric reader configuration: '' expected a map, got 'string'",
},
{
name: "valid pull reader type, no exporter",
cfg: confmap.NewFromStringMap(map[string]any{"pull": PullMetricReader{}}),
},
{
name: "valid pull reader type, invalid exporter",
cfg: confmap.NewFromStringMap(map[string]any{"pull": PullMetricReader{
Exporter: MetricExporter{
"invalid": "invalid",
},
}}),
err: "unsupported metric exporter type: invalid",
},
{
name: "valid pull reader type, invalid prometheus exporter",
cfg: confmap.NewFromStringMap(map[string]any{"pull": PullMetricReader{
Exporter: MetricExporter{
"prometheus": "invalid",
},
}}),
err: "invalid exporter configuration: '' expected a map, got 'string'",
},
{
name: "valid pull reader type, valid prometheus exporter",
cfg: confmap.NewFromStringMap(map[string]any{"pull": PullMetricReader{
Exporter: MetricExporter{
"prometheus": Prometheus{},
},
}}),
},
}
for _, tt := range tests {
reader := make(MeterProviderJsonMetricReaders)
err := reader.Unmarshal(tt.cfg)
assert.ErrorContains(t, err, tt.err)
if len(tt.err) > 0 {
assert.ErrorContains(t, err, tt.err)
} else {
assert.NoError(t, err)
}
}
}

0 comments on commit 2c8df44

Please sign in to comment.