Skip to content

Commit 2664aad

Browse files
committed
fix: Update ratelimit tests for v0.137.0 Optional API
- Use configoptional.Some() to wrap RateLimit values - Add _ struct{} to prevent unkeyed literal initialization - Add configoptional import - All tests now pass ✅
1 parent 5ce34ec commit 2664aad

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

config/confighttp/ratelimit.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
type RateLimit struct {
1717
// RateLimiterID specifies the name of the extension to use in order to rate limit the incoming data point.
1818
RateLimiterID component.ID `mapstructure:"rate_limiter"`
19+
// prevent unkeyed literal initialization
20+
_ struct{}
1921
}
2022

2123
type rateLimiter interface {

config/confighttp/ratelimit_test.go

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

1717
"go.opentelemetry.io/collector/component"
1818
"go.opentelemetry.io/collector/component/componenttest"
19+
"go.opentelemetry.io/collector/config/configoptional"
1920
)
2021

2122
func TestServerRateLimit(t *testing.T) {
2223
// prepare
2324
hss := ServerConfig{
2425
Endpoint: "localhost:0",
25-
RateLimit: &RateLimit{
26+
RateLimit: configoptional.Some(RateLimit{
2627
RateLimiterID: component.NewID(component.MustNewType("mock")),
27-
},
28+
}),
2829
}
2930

3031
limiter := &mockRateLimiter{}
@@ -53,9 +54,9 @@ func TestServerRateLimit(t *testing.T) {
5354

5455
func TestInvalidServerRateLimit(t *testing.T) {
5556
hss := ServerConfig{
56-
RateLimit: &RateLimit{
57+
RateLimit: configoptional.Some(RateLimit{
5758
RateLimiterID: component.NewID(component.MustNewType("non_existing")),
58-
},
59+
}),
5960
}
6061

6162
srv, err := hss.ToServer(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.NewServeMux())
@@ -67,9 +68,9 @@ func TestRejectedServerRateLimit(t *testing.T) {
6768
// prepare
6869
hss := ServerConfig{
6970
Endpoint: "localhost:0",
70-
RateLimit: &RateLimit{
71+
RateLimit: configoptional.Some(RateLimit{
7172
RateLimiterID: component.NewID(component.MustNewType("mock")),
72-
},
73+
}),
7374
}
7475
host := &mockHost{
7576
ext: map[component.ID]component.Component{

0 commit comments

Comments
 (0)