| 159 | } |
| 160 | |
| 161 | func startMockJS(ctx context.Context) (*mockJS, string) { |
| 162 | js := &mockJS{ |
| 163 | keys: make(map[string]*ttnpb.KeyEnvelope), |
| 164 | } |
| 165 | srv := rpcserver.New(ctx) |
| 166 | ttnpb.RegisterAsJsServer(srv.Server, js) |
| 167 | lis, err := net.Listen("tcp", ":0") |
| 168 | if err != nil { |
| 169 | panic(err) |
| 170 | } |
| 171 | go func() { |
| 172 | if err := srv.Serve(lis); err != nil { |
| 173 | panic(err) |
| 174 | } |
| 175 | }() |
| 176 | return js, lis.Addr().String() |
| 177 | } |
| 178 | |
| 179 | func (js *mockJS) add(ctx context.Context, devEUI types.EUI64, sessionKeyID []byte, key *ttnpb.KeyEnvelope) { |
| 180 | js.keys[fmt.Sprintf("%v:%v", devEUI, sessionKeyID)] = key |