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

Function TestServer

pkg/basicstation/cups/server_test.go:180–617  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178)
179
180func TestServer(t *testing.T) { //nolint:gocyclo
181 t.Parallel()
182 tlsServer := httptest.NewTLSServer(http.HandlerFunc(http.NotFound))
183 t.Cleanup(func() {
184 tlsServer.Close()
185 })
186 tlsServerURL, _ := url.Parse(tlsServer.URL)
187
188 cupsURI := (&url.URL{Scheme: "https", Host: tlsServerURL.Host}).String()
189 lnsURI := (&url.URL{Scheme: "wss", Host: tlsServerURL.Host}).String()
190
191 var kv config.KeyVault //nolint:gosimple
192
193 mockGateway := func(hasLNSSecret, redirectCUPS, updateCUPSCreds bool) *ttnpb.Gateway {
194 secret := &ttnpb.Secret{
195 KeyId: "test-key",
196 Value: []byte("KEYCONTENTS"),
197 }
198 gtw := ttnpb.Gateway{
199 Ids: &ttnpb.GatewayIdentifiers{
200 GatewayId: "test-gateway",
201 Eui: mockGatewayEUI.Bytes(),
202 },
203 Attributes: map[string]string{
204 cupsStationAttribute: "2.0.0(minihub/debug) 2018-12-06 09:30:35",
205 cupsModelAttribute: "minihub",
206 cupsPackageAttribute: "2.0.0",
207 },
208 GatewayServerAddress: lnsURI,
209 }
210 if hasLNSSecret {
211 gtw.LbsLnsSecret = secret
212 }
213 if redirectCUPS {
214 gtw.TargetCupsUri = cupsURI
215 gtw.TargetCupsKey = secret
216 }
217 if updateCUPSCreds {
218 gtw.TargetCupsKey = secret
219 }
220 return &gtw
221 }
222
223 for _, tt := range []struct {
224 Name string
225 StoreSetup func(*mockGatewayClient)
226 Options []Option
227 RequestSetup func(*http.Request)
228 SetContext func(ctx context.Context) context.Context
229 AssertError func(error) bool
230 AssertStore func(*assertions.Assertion, *mockGatewayClient)
231 AssertResponse func(*assertions.Assertion, *httptest.ResponseRecorder)
232 }{
233 {
234 Name: "No Auth",
235 StoreSetup: func(c *mockGatewayClient) {
236 c.res.Get = mockGateway(false, false, false)
237 c.res.GetIdentifiersForEUI = c.res.Get.GetIds()

Callers

nothing calls this directly

Calls 15

UnmarshalBinaryMethod · 0.95
updateInfoMethod · 0.95
IsUnauthenticatedFunction · 0.92
IsInvalidArgumentFunction · 0.92
IsNotFoundFunction · 0.92
ContextFunction · 0.92
NewContextFunction · 0.92
GetLoggerFunction · 0.92
NewContextWithFetcherFunction · 0.92
WithRegisterUnknownFunction · 0.85
WithDefaultLNSURIFunction · 0.85
WithAllowCUPSURIUpdateFunction · 0.85

Tested by

no test coverage detected