@@ -34,6 +34,7 @@ import (
3434 "go.thethings.network/lorawan-stack/v3/pkg/util/test"
3535 "go.thethings.network/lorawan-stack/v3/pkg/util/test/assertions/should"
3636 "google.golang.org/grpc"
37+ "google.golang.org/protobuf/types/known/emptypb"
3738)
3839
3940var (
@@ -182,7 +183,9 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
182183 CallOpt grpc.CallOption
183184 ClaimFunc func (context.Context , types.EUI64 , string , string ) (* dcstypes.GatewayMetadata , error )
184185 CreateFunc func (context.Context , * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error )
186+ UpdateFunc func (context.Context , * ttnpb.UpdateGatewayRequest ) (* ttnpb.Gateway , error )
185187 UnclaimFunc func (context.Context , types.EUI64 ) error
188+ DeleteFunc func (context.Context , * ttnpb.GatewayIdentifiers ) (* emptypb.Empty , error )
186189 ErrorAssertion func (error ) bool
187190 }{
188191 {
@@ -241,6 +244,25 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
241244 CallOpt : authorizedCallOpt ,
242245 ErrorAssertion : errors .IsAlreadyExists ,
243246 },
247+ {
248+ Name : "Claim/GatewayCreationFailed" ,
249+ Req : & ttnpb.ClaimGatewayRequest {
250+ Collaborator : userID .GetOrganizationOrUserIdentifiers (),
251+ SourceGateway : & ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers_ {
252+ AuthenticatedIdentifiers : & ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers {
253+ GatewayEui : supportedEUI .Bytes (),
254+ AuthenticationCode : claimAuthCode ,
255+ },
256+ },
257+ TargetGatewayId : "test-gateway" ,
258+ TargetGatewayServerAddress : "things.example.com" ,
259+ },
260+ CallOpt : authorizedCallOpt ,
261+ CreateFunc : func (_ context.Context , in * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
262+ return nil , errCreate .New ()
263+ },
264+ ErrorAssertion : errors .IsAborted ,
265+ },
244266 {
245267 Name : "Claim/EUINotRegisteredForClaiming" ,
246268 Req : & ttnpb.ClaimGatewayRequest {
@@ -254,7 +276,13 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
254276 TargetGatewayId : "test-gateway" ,
255277 TargetGatewayServerAddress : "things.example.com" ,
256278 },
257- CallOpt : authorizedCallOpt ,
279+ CallOpt : authorizedCallOpt ,
280+ CreateFunc : func (_ context.Context , in * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
281+ return in .Gateway , nil
282+ },
283+ DeleteFunc : func (_ context.Context , _ * ttnpb.GatewayIdentifiers ) (* emptypb.Empty , error ) {
284+ return & emptypb.Empty {}, nil
285+ },
258286 ErrorAssertion : errors .IsAborted ,
259287 },
260288 {
@@ -271,13 +299,22 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
271299 TargetGatewayServerAddress : "things.example.com" ,
272300 },
273301 CallOpt : authorizedCallOpt ,
302+ CreateFunc : func (_ context.Context , in * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
303+ return in .Gateway , nil
304+ },
274305 ClaimFunc : func (_ context.Context , _ types.EUI64 , _ , _ string ) (* dcstypes.GatewayMetadata , error ) {
275306 return nil , errClaim .New ()
276307 },
308+ UpdateFunc : func (_ context.Context , in * ttnpb.UpdateGatewayRequest ) (* ttnpb.Gateway , error ) {
309+ return in .Gateway , nil
310+ },
311+ DeleteFunc : func (_ context.Context , _ * ttnpb.GatewayIdentifiers ) (* emptypb.Empty , error ) {
312+ return & emptypb.Empty {}, nil
313+ },
277314 ErrorAssertion : errors .IsAborted ,
278315 },
279316 {
280- Name : "Claim/CreateFailed " ,
317+ Name : "Claim/UpdateFailed " ,
281318 Req : & ttnpb.ClaimGatewayRequest {
282319 Collaborator : userID .GetOrganizationOrUserIdentifiers (),
283320 SourceGateway : & ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers_ {
@@ -294,7 +331,13 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
294331 return & dcstypes.GatewayMetadata {}, nil
295332 },
296333 CreateFunc : func (context.Context , * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
297- return nil , errCreate .New ()
334+ return nil , nil
335+ },
336+ UpdateFunc : func (_ context.Context , in * ttnpb.UpdateGatewayRequest ) (* ttnpb.Gateway , error ) {
337+ return nil , errUpdate .New ()
338+ },
339+ DeleteFunc : func (_ context.Context , _ * ttnpb.GatewayIdentifiers ) (* emptypb.Empty , error ) {
340+ return & emptypb.Empty {}, nil
298341 },
299342 UnclaimFunc : func (_ context.Context , eui types.EUI64 ) error {
300343 if eui .Equal (supportedEUI ) {
@@ -305,7 +348,7 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
305348 ErrorAssertion : errors .IsAborted ,
306349 },
307350 {
308- Name : "Claim/CreateFailedWithUnclaimFailed " ,
351+ Name : "Claim/UpdateFailedWithUnclaimFailed " ,
309352 Req : & ttnpb.ClaimGatewayRequest {
310353 Collaborator : userID .GetOrganizationOrUserIdentifiers (),
311354 SourceGateway : & ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers_ {
@@ -322,15 +365,21 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
322365 return & dcstypes.GatewayMetadata {}, nil
323366 },
324367 CreateFunc : func (context.Context , * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
325- return nil , errCreate .New ()
368+ return nil , nil
369+ },
370+ UpdateFunc : func (_ context.Context , in * ttnpb.UpdateGatewayRequest ) (* ttnpb.Gateway , error ) {
371+ return nil , errUpdate .New ()
372+ },
373+ DeleteFunc : func (_ context.Context , _ * ttnpb.GatewayIdentifiers ) (* emptypb.Empty , error ) {
374+ return & emptypb.Empty {}, nil
326375 },
327376 UnclaimFunc : func (context.Context , types.EUI64 ) error {
328377 return errUnclaim .New ()
329378 },
330379 ErrorAssertion : errors .IsAborted ,
331380 },
332381 {
333- Name : "Claim/SuccessfullyClaimedAndCreated " ,
382+ Name : "Claim/SuccessfullyClaimedAndUpdated " ,
334383 Req : & ttnpb.ClaimGatewayRequest {
335384 Collaborator : userID .GetOrganizationOrUserIdentifiers (),
336385 SourceGateway : & ttnpb.ClaimGatewayRequest_AuthenticatedIdentifiers_ {
@@ -348,6 +397,9 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
348397 CreateFunc : func (_ context.Context , in * ttnpb.CreateGatewayRequest ) (* ttnpb.Gateway , error ) {
349398 return in .Gateway , nil
350399 },
400+ UpdateFunc : func (_ context.Context , in * ttnpb.UpdateGatewayRequest ) (* ttnpb.Gateway , error ) {
401+ return in .Gateway , nil
402+ },
351403 CallOpt : authorizedCallOpt ,
352404 },
353405 } {
@@ -361,6 +413,12 @@ func TestGatewayClaimingServer(t *testing.T) { //nolint:paralleltest
361413 if tc .CreateFunc != nil {
362414 mockGatewayRegistry .createFunc = tc .CreateFunc
363415 }
416+ if tc .UpdateFunc != nil {
417+ mockGatewayRegistry .updateFunc = tc .UpdateFunc
418+ }
419+ if tc .DeleteFunc != nil {
420+ mockGatewayRegistry .deleteFunc = tc .DeleteFunc
421+ }
364422
365423 _ , err := gclsClient .Claim (ctx , tc .Req , tc .CallOpt )
366424 if err != nil {
0 commit comments