@@ -181,10 +181,10 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
181181 Name string
182182 Req * ttnpb.ClaimGatewayRequest
183183 CallOpt grpc.CallOption
184- ClaimFunc func (context.Context , types. EUI64 , string , string ) (* dcstypes.GatewayMetadata , error )
184+ ClaimFunc func (context.Context , * ttnpb. GatewayIdentifiers , string , string ) (* dcstypes.GatewayMetadata , error )
185185 CreateFunc func (context.Context , * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error )
186186 UpdateFunc func (context.Context , * ttnpb.UpdateGatewayRequest ) (* ttnpb.Gateway , error )
187- UnclaimFunc func (context.Context , types. EUI64 ) error
187+ UnclaimFunc func (context.Context , * ttnpb. GatewayIdentifiers ) error
188188 DeleteFunc func (context.Context , * ttnpb.GatewayIdentifiers ) (* emptypb.Empty , error )
189189 ErrorAssertion func (error ) bool
190190 }{
@@ -302,7 +302,7 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
302302 CreateFunc : func (_ context.Context , in * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
303303 return in .Gateway , nil
304304 },
305- ClaimFunc : func (_ context.Context , _ types. EUI64 , _ , _ string ) (* dcstypes.GatewayMetadata , error ) {
305+ ClaimFunc : func (_ context.Context , _ * ttnpb. GatewayIdentifiers , _ , _ string ) (* dcstypes.GatewayMetadata , error ) {
306306 return nil , errClaim .New ()
307307 },
308308 UpdateFunc : func (_ context.Context , in * ttnpb.UpdateGatewayRequest ) (* ttnpb.Gateway , error ) {
@@ -327,7 +327,7 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
327327 TargetGatewayServerAddress : "things.example.com" ,
328328 },
329329 CallOpt : authorizedCallOpt ,
330- ClaimFunc : func (context.Context , types. EUI64 , string , string ) (* dcstypes.GatewayMetadata , error ) {
330+ ClaimFunc : func (context.Context , * ttnpb. GatewayIdentifiers , string , string ) (* dcstypes.GatewayMetadata , error ) {
331331 return & dcstypes.GatewayMetadata {}, nil
332332 },
333333 CreateFunc : func (context.Context , * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
@@ -339,8 +339,8 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
339339 DeleteFunc : func (_ context.Context , _ * ttnpb.GatewayIdentifiers ) (* emptypb.Empty , error ) {
340340 return & emptypb.Empty {}, nil
341341 },
342- UnclaimFunc : func (_ context.Context , eui types. EUI64 ) error {
343- if eui .Equal (supportedEUI ) {
342+ UnclaimFunc : func (_ context.Context , ids * ttnpb. GatewayIdentifiers ) error {
343+ if types . MustEUI64 ( ids . Eui ). OrZero () .Equal (supportedEUI ) {
344344 return nil
345345 }
346346 return errUnclaim .New ()
@@ -361,7 +361,7 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
361361 TargetGatewayServerAddress : "things.example.com" ,
362362 },
363363 CallOpt : authorizedCallOpt ,
364- ClaimFunc : func (context.Context , types. EUI64 , string , string ) (* dcstypes.GatewayMetadata , error ) {
364+ ClaimFunc : func (context.Context , * ttnpb. GatewayIdentifiers , string , string ) (* dcstypes.GatewayMetadata , error ) {
365365 return & dcstypes.GatewayMetadata {}, nil
366366 },
367367 CreateFunc : func (context.Context , * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
@@ -373,7 +373,7 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
373373 DeleteFunc : func (_ context.Context , _ * ttnpb.GatewayIdentifiers ) (* emptypb.Empty , error ) {
374374 return & emptypb.Empty {}, nil
375375 },
376- UnclaimFunc : func (context.Context , types. EUI64 ) error {
376+ UnclaimFunc : func (context.Context , * ttnpb. GatewayIdentifiers ) error {
377377 return errUnclaim .New ()
378378 },
379379 ErrorAssertion : errors .IsAborted ,
@@ -391,7 +391,66 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
391391 TargetGatewayId : "test-gateway" ,
392392 TargetGatewayServerAddress : "things.example.com" ,
393393 },
394- ClaimFunc : func (context.Context , types.EUI64 , string , string ) (* dcstypes.GatewayMetadata , error ) {
394+ ClaimFunc : func (context.Context , * ttnpb.GatewayIdentifiers , string , string ) (* dcstypes.GatewayMetadata , error ) {
395+ return & dcstypes.GatewayMetadata {}, nil
396+ },
397+ CreateFunc : func (_ context.Context , in * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
398+ return in .Gateway , nil
399+ },
400+ UpdateFunc : func (_ context.Context , in * ttnpb.UpdateGatewayRequest ) (* ttnpb.Gateway , error ) {
401+ return in .Gateway , nil
402+ },
403+ CallOpt : authorizedCallOpt ,
404+ },
405+ {
406+ Name : "Claim/EmptyTargetGatewayIDDefaultsToEUIAndDeletesOnFailedClaim" ,
407+ Req : & ttnpb.ClaimGatewayRequest {
408+ Collaborator : userID .GetOrganizationOrUserIdentifiers (),
409+ SourceGateway : & ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers_ {
410+ AuthenticatedIdentifiers : & ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers {
411+ GatewayEui : supportedEUI .Bytes (),
412+ AuthenticationCode : claimAuthCode ,
413+ },
414+ },
415+ TargetGatewayServerAddress : "things.example.com" ,
416+ },
417+ CallOpt : authorizedCallOpt ,
418+ ClaimFunc : func (
419+ _ context.Context , ids * ttnpb.GatewayIdentifiers , _ , _ string ,
420+ ) (* dcstypes.GatewayMetadata , error ) {
421+ a .So (ids .GatewayId , should .Equal , "58a0cbfffe800001" )
422+ a .So (ids .Eui , should .Resemble , supportedEUI .Bytes ())
423+ return nil , errClaim .New ()
424+ },
425+ CreateFunc : func (_ context.Context , in * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
426+ a .So (in .Gateway .GetIds ().GetGatewayId (), should .Equal , "58a0cbfffe800001" )
427+ return in .Gateway , nil
428+ },
429+ DeleteFunc : func (_ context.Context , ids * ttnpb.GatewayIdentifiers ) (* emptypb.Empty , error ) {
430+ a .So (ids .GatewayId , should .Equal , "58a0cbfffe800001" )
431+ a .So (ids .Eui , should .Resemble , supportedEUI .Bytes ())
432+ return & emptypb.Empty {}, nil
433+ },
434+ ErrorAssertion : errors .IsAborted ,
435+ },
436+ {
437+ Name : "Claim/ForwardsGatewayIdentifiers" ,
438+ Req : & ttnpb.ClaimGatewayRequest {
439+ Collaborator : userID .GetOrganizationOrUserIdentifiers (),
440+ SourceGateway : & ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers_ {
441+ AuthenticatedIdentifiers : & ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers {
442+ GatewayEui : supportedEUI .Bytes (),
443+ AuthenticationCode : claimAuthCode ,
444+ },
445+ },
446+ TargetGatewayId : "forwarded-gateway" ,
447+ TargetGatewayServerAddress : "things.example.com" ,
448+ },
449+ ClaimFunc : func (
450+ _ context.Context , ids * ttnpb.GatewayIdentifiers , _ , _ string ,
451+ ) (* dcstypes.GatewayMetadata , error ) {
452+ a .So (ids .GatewayId , should .Equal , "forwarded-gateway" )
453+ a .So (ids .Eui , should .Resemble , supportedEUI .Bytes ())
395454 return & dcstypes.GatewayMetadata {}, nil
396455 },
397456 CreateFunc : func (_ context.Context , in * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
@@ -437,7 +496,7 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
437496 Req * ttnpb.GatewayIdentifiers
438497 CallOpt grpc.CallOption
439498 GetFunc func (context.Context , * ttnpb.GetGatewayRequest ) (* ttnpb.Gateway , error )
440- UnclaimFunc func (context.Context , types. EUI64 ) error
499+ UnclaimFunc func (context.Context , * ttnpb. GatewayIdentifiers ) error
441500 ErrorAssertion func (error ) bool
442501 }{
443502 {
@@ -508,7 +567,7 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
508567 GatewayServerAddress : "test.example.com" ,
509568 }, nil
510569 },
511- UnclaimFunc : func (context.Context , types. EUI64 ) error {
570+ UnclaimFunc : func (context.Context , * ttnpb. GatewayIdentifiers ) error {
512571 return errUnclaim .New ()
513572 },
514573 CallOpt : authorizedCallOpt ,
@@ -528,7 +587,28 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
528587 GatewayServerAddress : "test.example.com" ,
529588 }, nil
530589 },
531- UnclaimFunc : func (context.Context , types.EUI64 ) error {
590+ UnclaimFunc : func (context.Context , * ttnpb.GatewayIdentifiers ) error {
591+ return nil
592+ },
593+ CallOpt : authorizedCallOpt ,
594+ },
595+ {
596+ Name : "Unclaim/ForwardsGatewayIdentifiers" ,
597+ Req : & ttnpb.GatewayIdentifiers {
598+ GatewayId : "forwarded-gateway" ,
599+ },
600+ GetFunc : func (context.Context , * ttnpb.GetGatewayRequest ) (* ttnpb.Gateway , error ) {
601+ return & ttnpb.Gateway {
602+ Ids : & ttnpb.GatewayIdentifiers {
603+ GatewayId : "forwarded-gateway" ,
604+ Eui : supportedEUI .Bytes (),
605+ },
606+ GatewayServerAddress : "test.example.com" ,
607+ }, nil
608+ },
609+ UnclaimFunc : func (_ context.Context , ids * ttnpb.GatewayIdentifiers ) error {
610+ a .So (ids .GatewayId , should .Equal , "forwarded-gateway" )
611+ a .So (ids .Eui , should .Resemble , supportedEUI .Bytes ())
532612 return nil
533613 },
534614 CallOpt : authorizedCallOpt ,
0 commit comments