Skip to content

Commit 4cd53ec

Browse files
committed
test: interface changed
1 parent df33e57 commit 4cd53ec

2 files changed

Lines changed: 11 additions & 36 deletions

File tree

internal/mocks.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,15 @@ func (m *MockCacheInvalidator) InvalidateCache(
183183
var _ ValidationResponseHandler = (*MockValidationResponseHandler)(nil)
184184

185185
type MockValidationResponseHandler struct {
186-
HandleValidationResponseFunc func(ctx RevalidationContext, req *http.Request, resp *http.Response, err error) (*http.Response, error)
186+
HandleValidationResponseFunc func(ctx RevalidationContext, req *http.Request, resp *http.Response) (*http.Response, error)
187187
}
188188

189189
func (m *MockValidationResponseHandler) HandleValidationResponse(
190190
ctx RevalidationContext,
191191
req *http.Request,
192192
resp *http.Response,
193-
err error,
194193
) (*http.Response, error) {
195-
return m.HandleValidationResponseFunc(ctx, req, resp, err)
194+
return m.HandleValidationResponseFunc(ctx, req, resp)
196195
}
197196

198197
var _ VaryMatcher = (*MockVaryMatcher)(nil)

internal/validationresponsehandler_test.go

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package internal
1616

1717
import (
18-
"errors"
1918
"log/slog"
2019
"net/http"
2120
"net/url"
@@ -48,9 +47,8 @@ func Test_validationResponseHandler_HandleValidationResponse(t *testing.T) {
4847
}
4948

5049
type args struct {
51-
req *http.Request
52-
resp *http.Response
53-
inputErr error
50+
req *http.Request
51+
resp *http.Response
5452
}
5553

5654
tests := []struct {
@@ -99,31 +97,7 @@ func Test_validationResponseHandler_HandleValidationResponse(t *testing.T) {
9997
},
10098
},
10199
{
102-
name: "GET with error, stale allowed",
103-
handler: &validationResponseHandler{
104-
l: noopLogger,
105-
siep: &MockStaleIfErrorPolicy{
106-
CanStaleOnErrorFunc: func(*Freshness, ...StaleIfErrorer) bool { return true },
107-
},
108-
clock: &MockClock{NowResult: base},
109-
},
110-
setup: func(tt *testing.T, handler *validationResponseHandler) args {
111-
return args{
112-
req: &http.Request{Method: http.MethodGet},
113-
resp: &http.Response{
114-
StatusCode: http.StatusInternalServerError,
115-
Header: http.Header{"Cache-Control": {"stale-if-error=60"}},
116-
},
117-
inputErr: errors.New("network error"),
118-
}
119-
},
120-
assert: func(tt *testing.T, got *http.Response, err error) {
121-
testutil.RequireNoError(tt, err)
122-
testutil.AssertEqual(tt, http.StatusOK, got.StatusCode)
123-
},
124-
},
125-
{
126-
name: "GET with error, stale not allowed",
100+
name: "GET with error status, stale not allowed",
127101
handler: &validationResponseHandler{
128102
l: noopLogger,
129103
siep: &MockStaleIfErrorPolicy{
@@ -132,18 +106,20 @@ func Test_validationResponseHandler_HandleValidationResponse(t *testing.T) {
132106
clock: &MockClock{NowResult: base},
133107
},
134108
setup: func(tt *testing.T, handler *validationResponseHandler) args {
109+
handler.ce = CacheabilityEvaluatorFunc(
110+
func(*http.Response, CCRequestDirectives, CCResponseDirectives) bool { return false },
111+
)
135112
return args{
136113
req: &http.Request{Method: http.MethodGet},
137114
resp: &http.Response{
138115
StatusCode: http.StatusInternalServerError,
139116
Header: http.Header{},
140117
},
141-
inputErr: errors.New("network error"),
142118
}
143119
},
144120
assert: func(tt *testing.T, got *http.Response, err error) {
145-
testutil.RequireError(tt, err)
146-
testutil.AssertNil(tt, got)
121+
testutil.RequireNoError(tt, err)
122+
testutil.AssertEqual(tt, "BYPASS", got.Header.Get(CacheStatusHeader))
147123
},
148124
},
149125
{
@@ -202,7 +178,7 @@ func Test_validationResponseHandler_HandleValidationResponse(t *testing.T) {
202178
for _, tt := range tests {
203179
t.Run(tt.name, func(t *testing.T) {
204180
a := tt.setup(t, tt.handler)
205-
got, err := tt.handler.HandleValidationResponse(ctx, a.req, a.resp, a.inputErr)
181+
got, err := tt.handler.HandleValidationResponse(ctx, a.req, a.resp)
206182
tt.assert(t, got, err)
207183
})
208184
}

0 commit comments

Comments
 (0)