Skip to content

Commit

Permalink
Add more unit tests in the otlp exporter for the config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
atmask committed Feb 23, 2024
1 parent 598ff85 commit 80c961f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions exporter/otlpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,3 +795,28 @@ func TestSendLogData(t *testing.T) {
assert.Len(t, observed.FilterLevelExact(zap.WarnLevel).All(), 1)
assert.Contains(t, observed.FilterLevelExact(zap.WarnLevel).All()[0].Message, "Partial success")
}

func TestExporterConfigValidation(t *testing.T) {
// Start an OTLP exporter and point to the receiver.
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)

// Validate that the error is thrown when no port is specified in the address
cfg.ClientConfig = configgrpc.ClientConfig{
Endpoint: "localhost",
}
assert.Error(t, cfg.Validate())

// Validate that missing endpoint fails validations
cfg.ClientConfig = configgrpc.ClientConfig{
Endpoint: "",
}
assert.Error(t, cfg.Validate())

// Validate a valid endpoint with port throws no error
cfg.ClientConfig = configgrpc.ClientConfig{
Endpoint: "localhost:1234",
}
assert.NoError(t, cfg.Validate())

}

0 comments on commit 80c961f

Please sign in to comment.