@@ -3,11 +3,9 @@ package keys
33import (
44 "testing"
55
6+ "github.com/stretchr/testify/assert"
67 "google.golang.org/protobuf/types/known/anypb"
78 "google.golang.org/protobuf/types/known/structpb"
8- "google.golang.org/protobuf/types/known/wrapperspb"
9-
10- "github.com/stretchr/testify/assert"
119
1210 "github.com/Permify/permify/pkg/cache/ristretto"
1311 "github.com/Permify/permify/pkg/logger"
@@ -22,7 +20,7 @@ func TestEngineKeys_SetCheckKey(t *testing.T) {
2220 l := logger .New ("debug" )
2321
2422 // Initialize a new EngineKeys struct with a new cache.Cache instance
25- engineKeys := CheckEngineWithKeys {nil , cache , l }
23+ engineKeys := CheckEngineWithKeys {nil , nil , cache , l }
2624
2725 // Create a new PermissionCheckRequest and PermissionCheckResponse
2826 checkReq := & base.PermissionCheckRequest {
@@ -51,15 +49,15 @@ func TestEngineKeys_SetCheckKey(t *testing.T) {
5149 }
5250
5351 // Set the value for the given key in the cache
54- success := engineKeys .setCheckKey (checkReq , checkResp )
52+ success := engineKeys .setCheckKey (checkReq , checkResp , true )
5553
5654 cache .Wait ()
5755
5856 // Check that the operation was successful
5957 assert .True (t , success )
6058
6159 // Retrieve the value for the given key from the cache
62- resp , found := engineKeys .getCheckKey (checkReq )
60+ resp , found := engineKeys .getCheckKey (checkReq , true )
6361
6462 // Check that the key was found and the retrieved value is the same as the original value
6563 assert .True (t , found )
@@ -74,7 +72,7 @@ func TestEngineKeys_SetCheckKey_WithHashError(t *testing.T) {
7472 l := logger .New ("debug" )
7573
7674 // Initialize a new EngineKeys struct with a new cache.Cache instance
77- engineKeys := CheckEngineWithKeys {nil , cache , l }
75+ engineKeys := CheckEngineWithKeys {nil , nil , cache , l }
7876
7977 // Create a new PermissionCheckRequest and PermissionCheckResponse
8078 checkReq := & base.PermissionCheckRequest {
@@ -103,15 +101,15 @@ func TestEngineKeys_SetCheckKey_WithHashError(t *testing.T) {
103101 }
104102
105103 // Force an error while writing the key to the hash object by passing a nil key
106- success := engineKeys .setCheckKey (nil , checkResp )
104+ success := engineKeys .setCheckKey (nil , checkResp , true )
107105
108106 cache .Wait ()
109107
110108 // Check that the operation was unsuccessful
111109 assert .False (t , success )
112110
113111 // Retrieve the value for the given key from the cache
114- resp , found := engineKeys .getCheckKey (checkReq )
112+ resp , found := engineKeys .getCheckKey (checkReq , true )
115113
116114 // Check that the key was not found
117115 assert .False (t , found )
@@ -126,7 +124,7 @@ func TestEngineKeys_GetCheckKey_KeyNotFound(t *testing.T) {
126124 l := logger .New ("debug" )
127125
128126 // Initialize a new EngineKeys struct with a new cache.Cache instance
129- engineKeys := CheckEngineWithKeys {nil , cache , l }
127+ engineKeys := CheckEngineWithKeys {nil , nil , cache , l }
130128
131129 // Create a new PermissionCheckRequest
132130 checkReq := & base.PermissionCheckRequest {
@@ -148,7 +146,7 @@ func TestEngineKeys_GetCheckKey_KeyNotFound(t *testing.T) {
148146 }
149147
150148 // Retrieve the value for a non-existent key from the cache
151- resp , found := engineKeys .getCheckKey (checkReq )
149+ resp , found := engineKeys .getCheckKey (checkReq , true )
152150
153151 // Check that the key was not found
154152 assert .False (t , found )
@@ -163,7 +161,7 @@ func TestEngineKeys_SetAndGetMultipleKeys(t *testing.T) {
163161 l := logger .New ("debug" )
164162
165163 // Initialize a new EngineKeys struct with a new cache.Cache instance
166- engineKeys := CheckEngineWithKeys {nil , cache , l }
164+ engineKeys := CheckEngineWithKeys {nil , nil , cache , l }
167165
168166 // Create some new PermissionCheckRequests and PermissionCheckResponses
169167 checkReq1 := & base.PermissionCheckRequest {
@@ -239,9 +237,9 @@ func TestEngineKeys_SetAndGetMultipleKeys(t *testing.T) {
239237 }
240238
241239 // Set the values for the given keys in the cache
242- success1 := engineKeys .setCheckKey (checkReq1 , checkResp1 )
243- success2 := engineKeys .setCheckKey (checkReq2 , checkResp2 )
244- success3 := engineKeys .setCheckKey (checkReq3 , checkResp3 )
240+ success1 := engineKeys .setCheckKey (checkReq1 , checkResp1 , true )
241+ success2 := engineKeys .setCheckKey (checkReq2 , checkResp2 , true )
242+ success3 := engineKeys .setCheckKey (checkReq3 , checkResp3 , true )
245243
246244 cache .Wait ()
247245
@@ -251,9 +249,9 @@ func TestEngineKeys_SetAndGetMultipleKeys(t *testing.T) {
251249 assert .True (t , success3 )
252250
253251 // Retrieve the value for the given key from the cache
254- resp1 , found1 := engineKeys .getCheckKey (checkReq1 )
255- resp2 , found2 := engineKeys .getCheckKey (checkReq2 )
256- resp3 , found3 := engineKeys .getCheckKey (checkReq3 )
252+ resp1 , found1 := engineKeys .getCheckKey (checkReq1 , true )
253+ resp2 , found2 := engineKeys .getCheckKey (checkReq2 , true )
254+ resp3 , found3 := engineKeys .getCheckKey (checkReq3 , true )
257255
258256 // Check that the key was not found
259257 assert .True (t , found1 )
@@ -274,7 +272,7 @@ func TestEngineKeys_SetCheckKeyWithArguments(t *testing.T) {
274272 l := logger .New ("debug" )
275273
276274 // Initialize a new EngineKeys struct with a new cache.Cache instance
277- engineKeys := CheckEngineWithKeys {nil , cache , l }
275+ engineKeys := CheckEngineWithKeys {nil , nil , cache , l }
278276
279277 // Create a new PermissionCheckRequest and PermissionCheckResponse
280278 checkReq := & base.PermissionCheckRequest {
@@ -319,23 +317,23 @@ func TestEngineKeys_SetCheckKeyWithArguments(t *testing.T) {
319317 }
320318
321319 // Set the value for the given key in the cache
322- success := engineKeys .setCheckKey (checkReq , checkResp )
320+ success := engineKeys .setCheckKey (checkReq , checkResp , true )
323321
324322 cache .Wait ()
325323
326324 // Check that the operation was successful
327325 assert .True (t , success )
328326
329327 // Retrieve the value for the given key from the cache
330- resp , found := engineKeys .getCheckKey (checkReq )
328+ resp , found := engineKeys .getCheckKey (checkReq , true )
331329
332330 // Check that the key was found and the retrieved value is the same as the original value
333331 assert .True (t , found )
334332 assert .Equal (t , checkResp , resp )
335333}
336334
337335func TestEngineKeys_SetCheckKeyWithContext (t * testing.T ) {
338- value , err := anypb .New (wrapperspb . Bool ( true ) )
336+ value , err := anypb .New (& base. BooleanValue { Data : true } )
339337 if err != nil {
340338 }
341339
@@ -407,5 +405,5 @@ func TestEngineKeys_SetCheckKeyWithContext(t *testing.T) {
407405 },
408406 }
409407
410- assert .Equal (t , "check|t1|test_version|test_snap_token|entity_type:entity_id#relation@subject_type:subject_id,entity_type:entity_id# is_public@ boolean:true,day_of_a_week:saturday,day_of_a_year:35|test-entity:e1# test-rule(test_argument_1,test_argument_2)@user:u1 " , GenerateKey (checkReq ))
408+ assert .Equal (t , "check|t1|test_version|test_snap_token|entity_type:entity_id#relation@subject_type:subject_id,entity_type:entity_id$ is_public| boolean:true,day_of_a_week:saturday,day_of_a_year:35|test-entity:e1$ test-rule(test_argument_1,test_argument_2)" , GenerateKey (checkReq , false ))
411409}
0 commit comments