@@ -269,40 +269,34 @@ func (*testRuntimeServer) GetBulkSecret(ctx context.Context, in *runtimev1pb.Get
269
269
}
270
270
271
271
func (t * testRuntimeServer ) TryLock (ctx context.Context , in * runtimev1pb.TryLockRequest ) (* runtimev1pb.TryLockResponse , error ) {
272
-
273
272
if len (t .lock [in .ResourceId ]) == 0 {
274
273
t .lock [in .ResourceId ] = in .LockOwner
275
- resp := & runtimev1pb.TryLockResponse {
274
+ return & runtimev1pb.TryLockResponse {
276
275
Success : true ,
277
- }
278
- return resp , nil
279
- } else {
280
- resp := & runtimev1pb.TryLockResponse {
281
- Success : false ,
282
- }
283
- return resp , nil
276
+ }, nil
284
277
}
278
+ // lock exist
279
+ return & runtimev1pb.TryLockResponse {
280
+ Success : false ,
281
+ }, nil
285
282
}
286
283
287
284
func (t * testRuntimeServer ) Unlock (ctx context.Context , in * runtimev1pb.UnlockRequest ) (* runtimev1pb.UnlockResponse , error ) {
288
- if len (t .lock [in .ResourceId ]) != 0 {
289
- if t .lock [in .ResourceId ] == in .LockOwner {
290
- delete (t .lock , in .ResourceId )
291
- resp := & runtimev1pb.UnlockResponse {
292
- Status : pb .UnlockResponse_SUCCESS ,
293
- }
294
- return resp , nil
295
- } else {
296
- resp := & runtimev1pb.UnlockResponse {
297
- Status : pb .UnlockResponse_LOCK_BELONG_TO_OTHERS ,
298
- }
299
- return resp , nil
300
- }
301
-
302
- } else {
303
- resp := & runtimev1pb.UnlockResponse {
285
+ // LOCK_UNEXIST
286
+ if len (t .lock [in .ResourceId ]) == 0 {
287
+ return & runtimev1pb.UnlockResponse {
304
288
Status : pb .UnlockResponse_LOCK_UNEXIST ,
305
- }
306
- return resp , nil
289
+ }, nil
307
290
}
291
+ // SUCCESS
292
+ if t .lock [in .ResourceId ] == in .LockOwner {
293
+ delete (t .lock , in .ResourceId )
294
+ return & runtimev1pb.UnlockResponse {
295
+ Status : pb .UnlockResponse_SUCCESS ,
296
+ }, nil
297
+ }
298
+ // LOCK_BELONG_TO_OTHERS
299
+ return & runtimev1pb.UnlockResponse {
300
+ Status : pb .UnlockResponse_LOCK_BELONG_TO_OTHERS ,
301
+ }, nil
308
302
}
0 commit comments