@@ -23,7 +23,7 @@ func (t *testDetector) FromData(_ context.Context, verify bool, _ []byte) ([]det
23
23
t .fromDataCallCount = t .fromDataCallCount + 1
24
24
var results []detectors.Result
25
25
for _ , r := range t .results {
26
- copy := detectors.Result {Redacted : r .Redacted , Raw : r .Raw , RawV2 : r .RawV2 }
26
+ copy := detectors.Result {Redacted : r .Redacted , Raw : r .Raw , RawV2 : r .RawV2 , DetectorType : r . DetectorType }
27
27
if verify {
28
28
copy .CopyVerificationInfo (& r )
29
29
}
@@ -49,7 +49,7 @@ func getResultCacheKey(t *testing.T, cache *VerificationCache, result detectors.
49
49
return string (key )
50
50
}
51
51
52
- func TestVerificationCacheFromData_Passthrough (t * testing.T ) {
52
+ func TestVerificationCache_FromData_Passthrough (t * testing.T ) {
53
53
detector := testDetector {results : []detectors.Result {
54
54
{Redacted : "hello" , Raw : []byte ("hello" ), RawV2 : []byte ("helloV2" ), Verified : true },
55
55
}}
@@ -69,7 +69,7 @@ func TestVerificationCacheFromData_Passthrough(t *testing.T) {
69
69
})
70
70
}
71
71
72
- func TestVerificationCacheFromData_VerifyFalseForceCacheUpdateFalse (t * testing.T ) {
72
+ func TestVerificationCache_FromData_VerifyFalseForceCacheUpdateFalse (t * testing.T ) {
73
73
detector := testDetector {results : []detectors.Result {
74
74
{Redacted : "hello" , Raw : []byte ("hello" ), RawV2 : []byte ("helloV2" ), Verified : true },
75
75
}}
@@ -96,7 +96,7 @@ func TestVerificationCacheFromData_VerifyFalseForceCacheUpdateFalse(t *testing.T
96
96
assert .Equal (t , int32 (0 ), metrics .ResultCacheMisses .Load ())
97
97
}
98
98
99
- func TestFromDataCached_VerifyFalseForceCacheUpdateTrue (t * testing.T ) {
99
+ func TestVerificationCache_FromData_VerifyFalseForceCacheUpdateTrue (t * testing.T ) {
100
100
detector := testDetector {results : []detectors.Result {
101
101
{Redacted : "hello" , Raw : []byte ("hello" ), RawV2 : []byte ("helloV2" ), Verified : true },
102
102
{Redacted : "world" , Raw : []byte ("world" ), RawV2 : []byte ("worldV2" ), Verified : false },
@@ -129,7 +129,7 @@ func TestFromDataCached_VerifyFalseForceCacheUpdateTrue(t *testing.T) {
129
129
assert .Equal (t , int32 (0 ), metrics .ResultCacheMisses .Load ())
130
130
}
131
131
132
- func TestFromDataCached_VerifyTrueForceCacheUpdateFalseAllCacheHits (t * testing.T ) {
132
+ func TestVerificationCache_FromData_VerifyTrueForceCacheUpdateFalseAllCacheHits (t * testing.T ) {
133
133
remoteResults := []detectors.Result {
134
134
{Redacted : "hello" , Raw : []byte ("hello" ), RawV2 : []byte ("helloV2" ), Verified : true },
135
135
{Redacted : "world" , Raw : []byte ("world" ), RawV2 : []byte ("worldV2" ), Verified : false },
@@ -169,7 +169,7 @@ func TestFromDataCached_VerifyTrueForceCacheUpdateFalseAllCacheHits(t *testing.T
169
169
assert .Equal (t , int32 (0 ), metrics .ResultCacheMisses .Load ())
170
170
}
171
171
172
- func TestFromDataCached_VerifyTrueForceCacheUpdateFalseCacheMiss (t * testing.T ) {
172
+ func TestVerificationCache_FromData_VerifyTrueForceCacheUpdateFalseCacheMiss (t * testing.T ) {
173
173
detector := testDetector {results : []detectors.Result {
174
174
{Redacted : "hello" , Raw : []byte ("hello" ), RawV2 : []byte ("helloV2" ), Verified : true },
175
175
{Redacted : "world" , Raw : []byte ("world" ), RawV2 : []byte ("worldV2" ), Verified : false },
@@ -205,7 +205,7 @@ func TestFromDataCached_VerifyTrueForceCacheUpdateFalseCacheMiss(t *testing.T) {
205
205
assert .Equal (t , int32 (1 ), metrics .ResultCacheHitsWasted .Load ())
206
206
}
207
207
208
- func TestFromDataCached_VerifyTrueForceCacheUpdateTrue (t * testing.T ) {
208
+ func TestVerificationCache_FromData_VerifyTrueForceCacheUpdateTrue (t * testing.T ) {
209
209
detector := testDetector {results : []detectors.Result {
210
210
{Redacted : "hello" , Raw : []byte ("hello" ), RawV2 : []byte ("helloV2" ), Verified : true },
211
211
{Redacted : "world" , Raw : []byte ("world" ), RawV2 : []byte ("worldV2" ), Verified : false },
@@ -238,3 +238,45 @@ func TestFromDataCached_VerifyTrueForceCacheUpdateTrue(t *testing.T) {
238
238
assert .Equal (t , int32 (0 ), metrics .ResultCacheMisses .Load ())
239
239
assert .Equal (t , int32 (0 ), metrics .ResultCacheHitsWasted .Load ())
240
240
}
241
+
242
+ func TestVerificationCache_FromData_SameRawDifferentType_CacheMiss (t * testing.T ) {
243
+ detector1 := testDetector {results : []detectors.Result {
244
+ {Redacted : "hello" , Raw : []byte ("hello" ), Verified : true , DetectorType : - 1 },
245
+ }}
246
+ detector2 := testDetector {results : []detectors.Result {
247
+ {Redacted : "hello" , Raw : []byte ("hello" ), Verified : true , DetectorType : - 2 },
248
+ }}
249
+ cache := New (simple .NewCache [detectors.Result ](), nil )
250
+ _ , err := cache .FromData (logContext .Background (), & detector1 , true , false , nil )
251
+ require .NoError (t , err )
252
+
253
+ res , err := cache .FromData (logContext .Background (), & detector2 , true , false , nil )
254
+
255
+ if assert .NoError (t , err ) {
256
+ if assert .Len (t , res , 1 ) {
257
+ assert .Equal (t , detectorspb .DetectorType (- 2 ), res [0 ].DetectorType )
258
+ }
259
+ }
260
+ assert .Len (t , cache .resultCache .Values (), 2 )
261
+ }
262
+
263
+ func TestVerificationCache_FromData_SameRawV2DifferentType_CacheMiss (t * testing.T ) {
264
+ detector1 := testDetector {results : []detectors.Result {
265
+ {Redacted : "hello" , RawV2 : []byte ("there" ), Verified : true , DetectorType : - 1 },
266
+ }}
267
+ detector2 := testDetector {results : []detectors.Result {
268
+ {Redacted : "hello" , RawV2 : []byte ("there" ), Verified : true , DetectorType : - 2 },
269
+ }}
270
+ cache := New (simple .NewCache [detectors.Result ](), nil )
271
+ _ , err := cache .FromData (logContext .Background (), & detector1 , true , false , nil )
272
+ require .NoError (t , err )
273
+
274
+ res , err := cache .FromData (logContext .Background (), & detector2 , true , false , nil )
275
+
276
+ if assert .NoError (t , err ) {
277
+ if assert .Len (t , res , 1 ) {
278
+ assert .Equal (t , detectorspb .DetectorType (- 2 ), res [0 ].DetectorType )
279
+ }
280
+ }
281
+ assert .Len (t , cache .resultCache .Values (), 2 )
282
+ }
0 commit comments