Skip to content

Commit 1135d10

Browse files
cih9088bartventer
authored andcommitted
test: interface changed
1 parent f517dc6 commit 1135d10

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 {
@@ -107,31 +105,7 @@ func Test_validationResponseHandler_HandleValidationResponse(t *testing.T) {
107105
},
108106
},
109107
{
110-
name: "GET with error, stale allowed",
111-
handler: &validationResponseHandler{
112-
l: noopLogger,
113-
siep: &MockStaleIfErrorPolicy{
114-
CanStaleOnErrorFunc: func(*Freshness, ...StaleIfErrorer) bool { return true },
115-
},
116-
clock: &MockClock{NowResult: base},
117-
},
118-
setup: func(tt *testing.T, handler *validationResponseHandler) args {
119-
return args{
120-
req: &http.Request{Method: http.MethodGet},
121-
resp: &http.Response{
122-
StatusCode: http.StatusInternalServerError,
123-
Header: http.Header{"Cache-Control": {"stale-if-error=60"}},
124-
},
125-
inputErr: errors.New("network error"),
126-
}
127-
},
128-
assert: func(tt *testing.T, got *http.Response, err error) {
129-
testutil.RequireNoError(tt, err)
130-
testutil.AssertEqual(tt, http.StatusOK, got.StatusCode)
131-
},
132-
},
133-
{
134-
name: "GET with error, stale not allowed",
108+
name: "GET with error status, stale not allowed",
135109
handler: &validationResponseHandler{
136110
l: noopLogger,
137111
siep: &MockStaleIfErrorPolicy{
@@ -140,18 +114,20 @@ func Test_validationResponseHandler_HandleValidationResponse(t *testing.T) {
140114
clock: &MockClock{NowResult: base},
141115
},
142116
setup: func(tt *testing.T, handler *validationResponseHandler) args {
117+
handler.ce = CacheabilityEvaluatorFunc(
118+
func(*http.Response, CCRequestDirectives, CCResponseDirectives) bool { return false },
119+
)
143120
return args{
144121
req: &http.Request{Method: http.MethodGet},
145122
resp: &http.Response{
146123
StatusCode: http.StatusInternalServerError,
147124
Header: http.Header{},
148125
},
149-
inputErr: errors.New("network error"),
150126
}
151127
},
152128
assert: func(tt *testing.T, got *http.Response, err error) {
153-
testutil.RequireError(tt, err)
154-
testutil.AssertNil(tt, got)
129+
testutil.RequireNoError(tt, err)
130+
testutil.AssertEqual(tt, "BYPASS", got.Header.Get(CacheStatusHeader))
155131
},
156132
},
157133
{
@@ -210,7 +186,7 @@ func Test_validationResponseHandler_HandleValidationResponse(t *testing.T) {
210186
for _, tt := range tests {
211187
t.Run(tt.name, func(t *testing.T) {
212188
a := tt.setup(t, tt.handler)
213-
got, err := tt.handler.HandleValidationResponse(ctx, a.req, a.resp, a.inputErr)
189+
got, err := tt.handler.HandleValidationResponse(ctx, a.req, a.resp)
214190
tt.assert(t, got, err)
215191
})
216192
}

0 commit comments

Comments
 (0)