(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func TestRoundtrip(t *testing.T) { |
| 69 | for _, tc := range []struct { |
| 70 | ID ttnpb.IDStringer |
| 71 | Expected string |
| 72 | Parser func(string) (ttnpb.IDStringer, error) |
| 73 | }{ |
| 74 | { |
| 75 | &ttnpb.ApplicationIdentifiers{ApplicationId: "foo"}, |
| 76 | "foo", |
| 77 | func(uid string) (ttnpb.IDStringer, error) { return ToApplicationID(uid) }, |
| 78 | }, |
| 79 | { |
| 80 | &ttnpb.ClientIdentifiers{ClientId: "foo"}, |
| 81 | "foo", |
| 82 | func(uid string) (ttnpb.IDStringer, error) { return ToClientID(uid) }, |
| 83 | }, |
| 84 | { |
| 85 | &ttnpb.EndDeviceIdentifiers{ |
| 86 | ApplicationIds: &ttnpb.ApplicationIdentifiers{ |
| 87 | ApplicationId: "foo-app", |
| 88 | }, |
| 89 | DeviceId: "foo-device", |
| 90 | }, |
| 91 | "foo-app.foo-device", |
| 92 | func(uid string) (ttnpb.IDStringer, error) { return ToDeviceID(uid) }, |
| 93 | }, |
| 94 | { |
| 95 | &ttnpb.GatewayIdentifiers{GatewayId: "foo"}, |
| 96 | "foo", |
| 97 | func(uid string) (ttnpb.IDStringer, error) { return ToGatewayID(uid) }, |
| 98 | }, |
| 99 | { |
| 100 | &ttnpb.OrganizationIdentifiers{OrganizationId: "foo"}, |
| 101 | "foo", |
| 102 | func(uid string) (ttnpb.IDStringer, error) { return ToOrganizationID(uid) }, |
| 103 | }, |
| 104 | { |
| 105 | &ttnpb.UserIdentifiers{UserId: "foo"}, |
| 106 | "foo", |
| 107 | func(uid string) (ttnpb.IDStringer, error) { return ToUserID(uid) }, |
| 108 | }, |
| 109 | } { |
| 110 | t.Run(fmt.Sprintf("%T", tc.ID), func(t *testing.T) { |
| 111 | a := assertions.New(t) |
| 112 | a.So(ID(test.Context(), tc.ID), should.Equal, tc.Expected) |
| 113 | if id, ok := tc.ID.(interface { |
| 114 | GetEntityIdentifiers() *ttnpb.EntityIdentifiers |
| 115 | }); ok { |
| 116 | wrapped := id.GetEntityIdentifiers() |
| 117 | a.So(ID(test.Context(), wrapped), should.Equal, tc.Expected) |
| 118 | } |
| 119 | a.So(ID(test.Context(), tc.ID), should.Equal, tc.Expected) |
| 120 | if tc.Parser != nil { |
| 121 | parsed, err := tc.Parser(tc.Expected) |
| 122 | if a.So(err, should.BeNil) { |
| 123 | a.So(parsed.EntityType(), should.Resemble, tc.ID.EntityType()) |
| 124 | a.So(parsed.IDString(), should.Resemble, tc.ID.IDString()) |
| 125 | } |
nothing calls this directly
no test coverage detected