1515package internal
1616
1717import (
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