Skip to content

Commit

Permalink
Fix the unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidtw committed Dec 13, 2017
1 parent 8c310fc commit 0d75cea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/caduceus/caduceus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ func TestMuxServerConfig(t *testing.T) {
return errors.New("time out!")
}

fakeEmptyRequests := new(mockCounter)
fakeEmptyRequests.On("Add", mock.AnythingOfType("float64")).Return().Times(0)

serverWrapper := &ServerHandler{
Logger: logger,
caduceusHandler: fakeHandler,
caduceusHealth: fakeHealth,
emptyRequests: fakeEmptyRequests,
doJob: forceTimeOut,
}

Expand Down
4 changes: 4 additions & 0 deletions src/caduceus/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ func TestServerHandler(t *testing.T) {
return nil
}

fakeEmptyRequests := new(mockCounter)
fakeEmptyRequests.On("Add", mock.AnythingOfType("float64")).Return().Times(0)

serverWrapper := &ServerHandler{
Logger: logger,
caduceusHandler: fakeHandler,
caduceusHealth: fakeHealth,
emptyRequests: fakeEmptyRequests,
doJob: requestSuccessful,
}

Expand Down
15 changes: 15 additions & 0 deletions src/caduceus/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"github.com/Comcast/webpa-common/health"
"github.com/Comcast/webpa-common/webhook"
"github.com/go-kit/kit/metrics"
"github.com/stretchr/testify/mock"
"net/http"
"time"
Expand Down Expand Up @@ -116,3 +117,17 @@ func (m *mockServerProfiler) Report() (values []interface{}) {
func (m *mockServerProfiler) Close() {
m.Called()
}

// mockCounter provides the mock implementation of the metrics.Counter object
type mockCounter struct {
mock.Mock
}

func (m *mockCounter) Add(delta float64) {
m.Called(delta)
}

func (m *mockCounter) With(labelValues ...string) metrics.Counter {
m.Called(labelValues)
return nil
}

0 comments on commit 0d75cea

Please sign in to comment.