From 4c6e8ca9cc9591799907cc73075f2d740e303b8f Mon Sep 17 00:00:00 2001 From: Ori <59772293+orizerah@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:59:54 +0530 Subject: [PATCH] feat(server): Make Trivy Server Multiplexer Exported (#7389) --- pkg/rpc/server/listen.go | 4 ++-- pkg/rpc/server/listen_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/rpc/server/listen.go b/pkg/rpc/server/listen.go index 2b6d1288b7ff..f1e39fa1b2f0 100644 --- a/pkg/rpc/server/listen.go +++ b/pkg/rpc/server/listen.go @@ -72,13 +72,13 @@ func (s Server) ListenAndServe(ctx context.Context, serverCache cache.Cache, ski } }() - mux := s.newServeMux(ctx, serverCache, dbUpdateWg, requestWg) + mux := s.NewServeMux(ctx, serverCache, dbUpdateWg, requestWg) log.Infof("Listening %s...", s.addr) return http.ListenAndServe(s.addr, mux) } -func (s Server) newServeMux(ctx context.Context, serverCache cache.Cache, dbUpdateWg, requestWg *sync.WaitGroup) *http.ServeMux { +func (s Server) NewServeMux(ctx context.Context, serverCache cache.Cache, dbUpdateWg, requestWg *sync.WaitGroup) *http.ServeMux { withWaitGroup := func(base http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Stop processing requests during DB update diff --git a/pkg/rpc/server/listen_test.go b/pkg/rpc/server/listen_test.go index fa61e228806c..7f97bdbcb31e 100644 --- a/pkg/rpc/server/listen_test.go +++ b/pkg/rpc/server/listen_test.go @@ -183,7 +183,7 @@ func TestServer_newServeMux(t *testing.T) { defer func() { _ = c.Close() }() s := NewServer("", "", "", tt.args.token, tt.args.tokenHeader, "", nil, ftypes.RegistryOptions{}) - ts := httptest.NewServer(s.newServeMux(context.Background(), c, dbUpdateWg, requestWg)) + ts := httptest.NewServer(s.NewServeMux(context.Background(), c, dbUpdateWg, requestWg)) defer ts.Close() var resp *http.Response @@ -214,7 +214,7 @@ func Test_VersionEndpoint(t *testing.T) { defer func() { _ = c.Close() }() s := NewServer("", "", "testdata/testcache", "", "", "", nil, ftypes.RegistryOptions{}) - ts := httptest.NewServer(s.newServeMux(context.Background(), c, dbUpdateWg, requestWg)) + ts := httptest.NewServer(s.NewServeMux(context.Background(), c, dbUpdateWg, requestWg)) defer ts.Close() resp, err := http.Get(ts.URL + "/version")