MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestEntityFetcherFunc

Function TestEntityFetcherFunc

pkg/auth/rights/fetcher_test.go:170–203  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

168}
169
170func 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
205func TestAuthInfoFetcherFunc(t *testing.T) {
206 a := assertions.New(t)

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
EntityFetcherFuncFuncType · 0.92
ContextFunction · 0.92
fetchEntityRightsFunction · 0.85
NewMethod · 0.65
GetEntityIdentifiersMethod · 0.65

Tested by

no test coverage detected