Skip to content

Commit

Permalink
feat(server): Make Trivy Server Multiplexer Exported (#7389)
Browse files Browse the repository at this point in the history
  • Loading branch information
orizerah authored Aug 29, 2024
1 parent 84118d0 commit 4c6e8ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/rpc/server/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/rpc/server/listen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 4c6e8ca

Please sign in to comment.