@@ -106,7 +106,7 @@ func Test_CacheMatcher_PreloadCache_WillPreemptivelyCacheFullExactMatchRequestMa
106106
107107 simulation := models .NewSimulation ()
108108
109- simulation . AddPair ( & models.RequestMatcherResponsePair {
109+ pair1 := & models.RequestMatcherResponsePair {
110110 RequestMatcher : models.RequestMatcher {
111111 Body : []models.RequestFieldMatchers {
112112 {
@@ -148,14 +148,79 @@ func Test_CacheMatcher_PreloadCache_WillPreemptivelyCacheFullExactMatchRequestMa
148148 },
149149 Response : models.ResponseDetails {
150150 Status : 200 ,
151- Body : "body" ,
151+ Body : "body 1 " ,
152152 },
153- })
153+ }
154+
155+ pair2 := & models.RequestMatcherResponsePair {
156+ RequestMatcher : models.RequestMatcher {
157+ Body : []models.RequestFieldMatchers {
158+ {
159+ Matcher : matchers .Exact ,
160+ Value : "body" ,
161+ },
162+ },
163+
164+ Destination : []models.RequestFieldMatchers {
165+ {
166+ Matcher : matchers .Exact ,
167+ Value : "destination" ,
168+ },
169+ },
170+ Method : []models.RequestFieldMatchers {
171+ {
172+ Matcher : matchers .Exact ,
173+ Value : "method" ,
174+ },
175+ },
176+ Path : []models.RequestFieldMatchers {
177+ {
178+ Matcher : matchers .Exact ,
179+ Value : "path" ,
180+ },
181+ },
182+ Query : & models.QueryRequestFieldMatchers {
183+ "queryKey" : {
184+ {
185+ Matcher : matchers .Exact ,
186+ Value : "queryValue" ,
187+ },
188+ },
189+ },
190+ Scheme : []models.RequestFieldMatchers {
191+ {
192+ Matcher : matchers .Exact ,
193+ Value : "scheme" ,
194+ },
195+ },
196+ },
197+ Response : models.ResponseDetails {
198+ Status : 200 ,
199+ Body : "body 2" ,
200+ },
201+ }
202+ simulation .AddPair (pair1 )
203+ simulation .AddPair (pair2 )
154204
155205 err := unit .PreloadCache (simulation )
156206
157207 Expect (err ).To (BeNil ())
158- Expect (unit .RequestCache .RecordsCount ()).To (Equal (1 ))
208+ Expect (unit .RequestCache .RecordsCount ()).To (Equal (2 ))
209+
210+ cacheable1 := * pair1 .RequestMatcher .ToEagerlyCacheable ()
211+ cached1 , _ := unit .RequestCache .Get (cacheable1 .Hash ())
212+ var cachedResponse1 * models.CachedResponse
213+ cachedResponse1 = cached1 .(* models.CachedResponse )
214+ Expect (cachedResponse1 .MatchingPair .Response .Body ).To (Equal ("body 1" ))
215+ Expect (cachedResponse1 .MatchingPair .RequestMatcher .Query ).To (BeNil ())
216+
217+ cacheable2 := * pair2 .RequestMatcher .ToEagerlyCacheable ()
218+ cached2 , _ := unit .RequestCache .Get (cacheable2 .Hash ())
219+ var cachedResponse2 * models.CachedResponse
220+ cachedResponse2 = cached2 .(* models.CachedResponse )
221+ Expect (cachedResponse2 .MatchingPair .Response .Body ).To (Equal ("body 2" ))
222+ Expect (cachedResponse2 .MatchingPair .RequestMatcher .Query .Get ("queryKey" )[0 ].Matcher ).To (Equal (matchers .Exact ))
223+ Expect (cachedResponse2 .MatchingPair .RequestMatcher .Query .Get ("queryKey" )[0 ].Value ).To (Equal ("queryValue" ))
159224}
160225
161226func Test_CacheMatcher_PreloadCache_WillNotPreemptivelyCacheRequestMatchersWithoutExactMatches (t * testing.T ) {
0 commit comments