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 {
@@ -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