(t *testing.T)
| 168 | } |
| 169 | |
| 170 | func TestEntityFetcherFunc(t *testing.T) { |
| 171 | a := assertions.New(t) |
| 172 | |
| 173 | var fetcher struct { |
| 174 | mu sync.Mutex |
| 175 | ctx []context.Context |
| 176 | ids []*ttnpb.EntityIdentifiers |
| 177 | rights *ttnpb.Rights |
| 178 | err error |
| 179 | } |
| 180 | fetcher.err = errors.New("test err") |
| 181 | f := rights.EntityFetcherFunc(func(ctx context.Context, ids *ttnpb.EntityIdentifiers) (*ttnpb.Rights, error) { |
| 182 | fetcher.mu.Lock() |
| 183 | defer fetcher.mu.Unlock() |
| 184 | fetcher.ctx = append(fetcher.ctx, ctx) |
| 185 | fetcher.ids = append(fetcher.ids, ids) |
| 186 | return fetcher.rights, fetcher.err |
| 187 | }) |
| 188 | |
| 189 | res := fetchEntityRights(test.Context(), "foo", f) |
| 190 | a.So(res.AppErr, should.Resemble, fetcher.err) |
| 191 | a.So(res.CliErr, should.Resemble, fetcher.err) |
| 192 | a.So(res.GtwErr, should.Resemble, fetcher.err) |
| 193 | a.So(res.OrgErr, should.Resemble, fetcher.err) |
| 194 | a.So(res.UsrErr, should.Resemble, fetcher.err) |
| 195 | |
| 196 | if a.So(fetcher.ids, should.HaveLength, 5) { |
| 197 | a.So(fetcher.ids, should.Contain, (&ttnpb.ApplicationIdentifiers{ApplicationId: "foo"}).GetEntityIdentifiers()) |
| 198 | a.So(fetcher.ids, should.Contain, (&ttnpb.ClientIdentifiers{ClientId: "foo"}).GetEntityIdentifiers()) |
| 199 | a.So(fetcher.ids, should.Contain, (&ttnpb.GatewayIdentifiers{GatewayId: "foo"}).GetEntityIdentifiers()) |
| 200 | a.So(fetcher.ids, should.Contain, (&ttnpb.OrganizationIdentifiers{OrganizationId: "foo"}).GetEntityIdentifiers()) |
| 201 | a.So(fetcher.ids, should.Contain, (&ttnpb.UserIdentifiers{UserId: "foo"}).GetEntityIdentifiers()) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | func TestAuthInfoFetcherFunc(t *testing.T) { |
| 206 | a := assertions.New(t) |
nothing calls this directly
no test coverage detected