Skip to content

Commit

Permalink
improve test coverage of http server (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
localvar committed May 7, 2022
1 parent df557d2 commit 0f802e6
Show file tree
Hide file tree
Showing 6 changed files with 618 additions and 550 deletions.
46 changes: 46 additions & 0 deletions pkg/context/contexttest/contexttest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2017, MegaEase
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package contexttest

import "github.com/megaease/easegress/pkg/context"

// MockedMuxMapper is a mux mapper for mocking in testing.
type MockedMuxMapper struct {
MockedGetHandler func(name string) (context.Handler, bool)
}

// GetHandler implements context.MuxMapper.
func (mmm *MockedMuxMapper) GetHandler(name string) (context.Handler, bool) {
if mmm.MockedGetHandler == nil {
return nil, false
}
return mmm.MockedGetHandler(name)
}

// MockedHandler is a mocked handler for mocking in testing.
type MockedHandler struct {
MockedHandle func(ctx *context.Context) string
}

// Handle implements context.Handler.
func (mh *MockedHandler) Handle(ctx *context.Context) string {
if mh.MockedHandle == nil {
return ""
}
return mh.MockedHandle(ctx)
}
1 change: 0 additions & 1 deletion pkg/object/httpserver/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (hs *HTTPServer) DefaultSpec() interface{} {

// Init initializes HTTPServer.
func (hs *HTTPServer) Init(superSpec *supervisor.Spec, muxMapper context.MuxMapper) {

hs.runtime = newRuntime(superSpec, muxMapper)

hs.runtime.eventChan <- &eventReload{
Expand Down
Loading

0 comments on commit 0f802e6

Please sign in to comment.