func Test_CacheInvalidationHandler_Delegate_Is_Called(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() //given handlerMock := mockhttp.NewMockHandler(ctrl) cacheMocK := NewMockCache(ctrl) cih := NewCacheInvalidationHandler(cacheMocK, handlerMock) request, _ := http.NewRequest(http.MethodDelete, "internal/cache", nil) //when cacheMocK.EXPECT().Invalidate().AnyTimes() handlerMock.EXPECT().ServeHTTP(gomock.Any(), gomock.Any()).Times(1) cih.ServeHTTP(nil, request) }
func Test_DelegateIsCalled(t *testing.T) { ctl := gomock.NewController(t) defer ctl.Finish() mockDelegator := mockHttp.NewMockHandler(ctl) fhh := NewForwardedHostHandler(mockDelegator) req, _ := http.NewRequest("GET", "", nil) resp := httptest.NewRecorder() //expected the delegate should not been called mockDelegator.EXPECT().ServeHTTP(gomock.Any(), gomock.Any()).Times(1) // when fhh.ServeHTTP(resp, req) }