|
| 1 | +// Copyright © 2025 The Things Network Foundation, The Things Industries B.V. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package ttnpb_test |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "go.thethings.network/lorawan-stack/v3/pkg/ttnpb" |
| 21 | +) |
| 22 | + |
| 23 | +func TestCreateApplicationRequest_RateLimitKey(t *testing.T) { |
| 24 | + t.Parallel() |
| 25 | + tests := []struct { |
| 26 | + name string |
| 27 | + req *ttnpb.CreateApplicationRequest |
| 28 | + expected string |
| 29 | + }{ |
| 30 | + { |
| 31 | + name: "valid request with user collaborator", |
| 32 | + req: &ttnpb.CreateApplicationRequest{ |
| 33 | + Application: &ttnpb.Application{ |
| 34 | + Ids: &ttnpb.ApplicationIdentifiers{ |
| 35 | + ApplicationId: "test-app-1", |
| 36 | + }, |
| 37 | + }, |
| 38 | + Collaborator: &ttnpb.OrganizationOrUserIdentifiers{ |
| 39 | + Ids: &ttnpb.OrganizationOrUserIdentifiers_UserIds{ |
| 40 | + UserIds: &ttnpb.UserIdentifiers{ |
| 41 | + UserId: "test-user", |
| 42 | + }, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + expected: "", |
| 47 | + }, |
| 48 | + { |
| 49 | + name: "different app same user", |
| 50 | + req: &ttnpb.CreateApplicationRequest{ |
| 51 | + Application: &ttnpb.Application{ |
| 52 | + Ids: &ttnpb.ApplicationIdentifiers{ |
| 53 | + ApplicationId: "test-app-2", |
| 54 | + }, |
| 55 | + }, |
| 56 | + Collaborator: &ttnpb.OrganizationOrUserIdentifiers{ |
| 57 | + Ids: &ttnpb.OrganizationOrUserIdentifiers_UserIds{ |
| 58 | + UserIds: &ttnpb.UserIdentifiers{ |
| 59 | + UserId: "test-user", |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + expected: "", |
| 65 | + }, |
| 66 | + { |
| 67 | + name: "valid request with organization collaborator", |
| 68 | + req: &ttnpb.CreateApplicationRequest{ |
| 69 | + Application: &ttnpb.Application{ |
| 70 | + Ids: &ttnpb.ApplicationIdentifiers{ |
| 71 | + ApplicationId: "test-app-3", |
| 72 | + }, |
| 73 | + }, |
| 74 | + Collaborator: &ttnpb.OrganizationOrUserIdentifiers{ |
| 75 | + Ids: &ttnpb.OrganizationOrUserIdentifiers_OrganizationIds{ |
| 76 | + OrganizationIds: &ttnpb.OrganizationIdentifiers{ |
| 77 | + OrganizationId: "test-org", |
| 78 | + }, |
| 79 | + }, |
| 80 | + }, |
| 81 | + }, |
| 82 | + expected: "", |
| 83 | + }, |
| 84 | + { |
| 85 | + name: "nil collaborator", |
| 86 | + req: &ttnpb.CreateApplicationRequest{ |
| 87 | + Application: &ttnpb.Application{ |
| 88 | + Ids: &ttnpb.ApplicationIdentifiers{ |
| 89 | + ApplicationId: "test-app", |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + expected: "", |
| 94 | + }, |
| 95 | + { |
| 96 | + name: "nil request", |
| 97 | + req: &ttnpb.CreateApplicationRequest{}, |
| 98 | + expected: "", |
| 99 | + }, |
| 100 | + } |
| 101 | + |
| 102 | + for _, tt := range tests { |
| 103 | + t.Run(tt.name, func(t *testing.T) { |
| 104 | + t.Parallel() |
| 105 | + got := tt.req.RateLimitKey() |
| 106 | + if got != tt.expected { |
| 107 | + t.Errorf("RateLimitKey() = %v, want %v", got, tt.expected) |
| 108 | + } |
| 109 | + }) |
| 110 | + } |
| 111 | +} |
0 commit comments