Skip to content

Commit

Permalink
Fix ratelimit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steves-canva committed May 9, 2024
1 parent 642b1b8 commit 23c88f8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions config/confighttp/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ import (

func TestServerRateLimit(t *testing.T) {
// prepare
hss := HTTPServerSettings{
hss := ServerConfig{
Endpoint: "localhost:0",
RateLimit: &RateLimit{
RateLimiterID: component.NewID("mock"),
RateLimiterID: component.NewID(component.MustNewType("mock")),
},
}

limiter := &mockRateLimiter{}

host := &mockHost{
ext: map[component.ID]component.Component{
component.NewID("mock"): limiter,
component.NewID(component.MustNewType("mock")): limiter,
},
}

Expand All @@ -39,7 +39,7 @@ func TestServerRateLimit(t *testing.T) {
handlerCalled = true
})

srv, err := hss.ToServer(host, componenttest.NewNopTelemetrySettings(), handler)
srv, err := hss.ToServer(context.Background(), host, componenttest.NewNopTelemetrySettings(), handler)
require.NoError(t, err)

// test
Expand All @@ -51,34 +51,34 @@ func TestServerRateLimit(t *testing.T) {
}

func TestInvalidServerRateLimit(t *testing.T) {
hss := HTTPServerSettings{
hss := ServerConfig{
RateLimit: &RateLimit{
RateLimiterID: component.NewID("non-existing"),
RateLimiterID: component.NewID(component.MustNewType("non_existing")),
},
}

srv, err := hss.ToServer(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.NewServeMux())
srv, err := hss.ToServer(context.Background(), componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), http.NewServeMux())
require.Error(t, err)
require.Nil(t, srv)
}

func TestRejectedServerRateLimit(t *testing.T) {
// prepare
hss := HTTPServerSettings{
hss := ServerConfig{
Endpoint: "localhost:0",
RateLimit: &RateLimit{
RateLimiterID: component.NewID("mock"),
RateLimiterID: component.NewID(component.MustNewType("mock")),
},
}
host := &mockHost{
ext: map[component.ID]component.Component{
component.NewID("mock"): &mockRateLimiter{
component.NewID(component.MustNewType("mock")): &mockRateLimiter{
err: errors.New("rate limited"),
},
},
}

srv, err := hss.ToServer(host, componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
srv, err := hss.ToServer(context.Background(), host, componenttest.NewNopTelemetrySettings(), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
require.NoError(t, err)

// test
Expand Down

0 comments on commit 23c88f8

Please sign in to comment.