Skip to content

Commit 5753e34

Browse files
Danielius1922Daniel Adam
authored and
Daniel Adam
committed
cloud: use valid uuid for sid property in tests
1 parent 02c11b1 commit 5753e34

24 files changed

+42
-41
lines changed

bridge/device/cloud/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
// device is restarted with an imported configuration with valid cloud credentials
3939
func TestProvisioningOnDeviceRestart(t *testing.T) {
4040
ch := mockCoapGW.NewCoapHandlerWithCounter(-1)
41-
makeHandler := func(s *mockCoapGWService.Service, opts ...mockCoapGWService.Option) mockCoapGWService.ServiceHandler {
41+
makeHandler := func(*mockCoapGWService.Service, ...mockCoapGWService.Option) mockCoapGWService.ServiceHandler {
4242
return ch
4343
}
4444
coapShutdown := mockCoapGW.New(t, makeHandler, func(handler mockCoapGWService.ServiceHandler) {

bridge/device/credential/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (m *Manager) importConfig(cfg Config) {
5757

5858
func (m *Manager) GetCAPool() []*x509.Certificate {
5959
certs := make([]*x509.Certificate, 0, m.credentials.Length())
60-
m.credentials.Range(func(key int, value credential.Credential) bool {
60+
m.credentials.Range(func(_ int, value credential.Credential) bool {
6161
if value.Type != credential.CredentialType_ASYMMETRIC_SIGNING_WITH_CERTIFICATE {
6262
return true
6363
}
@@ -76,7 +76,7 @@ func (m *Manager) GetCAPool() []*x509.Certificate {
7676

7777
func (m *Manager) getNextID() int {
7878
var id int
79-
m.credentials.Range(func(key int, value credential.Credential) bool {
79+
m.credentials.Range(func(key int, _ credential.Credential) bool {
8080
if key > id {
8181
id = key
8282
}

bridge/device/device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (d *Device) ExportConfig() Config {
109109

110110
func New(cfg Config, opts ...Option) (*Device, error) {
111111
o := OptionsCfg{
112-
onDeviceUpdated: func(d *Device) {
112+
onDeviceUpdated: func(*Device) {
113113
// do nothing
114114
},
115115
getAdditionalProperties: func() map[string]interface{} { return nil },

bridge/resources/discovery/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/plgd-dev/go-coap/v3/message/pool"
2929
)
3030

31-
type GetLinksHandler func(request *net.Request) schema.ResourceLinks
31+
type GetLinksHandler func(*net.Request) schema.ResourceLinks
3232

3333
type Resource struct {
3434
*resources.Resource

bridge/resources/resource.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ import (
3737
"go.uber.org/atomic"
3838
)
3939

40-
type GetHandlerFunc func(req *net.Request) (*pool.Message, error)
40+
type GetHandlerFunc func(*net.Request) (*pool.Message, error)
4141

42-
type PostHandlerFunc func(req *net.Request) (*pool.Message, error)
42+
type PostHandlerFunc func(*net.Request) (*pool.Message, error)
4343

44-
type CreateSubscriptionFunc func(req *net.Request, handler func(msg *pool.Message, err error)) (cancel func(), err error)
44+
type CreateSubscriptionFunc func(*net.Request, func(*pool.Message, error)) (func(), error)
4545

4646
const PublishToCloud schema.BitMask = 1 << 7
4747

@@ -166,7 +166,7 @@ func (r *Resource) Close() {
166166
if !r.closed.CompareAndSwap(false, true) {
167167
return
168168
}
169-
r.createdSubscription.Range(func(key string, value *subscription) bool {
169+
r.createdSubscription.Range(func(_ string, value *subscription) bool {
170170
value.cancel()
171171
return true
172172
})
@@ -192,7 +192,7 @@ func (r *Resource) watchSubscriptions() {
192192
}
193193
// resource closed
194194
// cancel all subscriptions
195-
r.createdSubscription.Range(func(key string, value *subscription) bool {
195+
r.createdSubscription.Range(func(_ string, value *subscription) bool {
196196
value.cancel()
197197
return true
198198
})

bridge/service/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import (
2424
)
2525

2626
type OptionsCfg struct {
27-
onDiscoveryDevices func(req *net.Request)
27+
onDiscoveryDevices func(*net.Request)
2828
logger log.Logger
2929
}
3030

31-
func WithOnDiscoveryDevices(f func(req *net.Request)) Option {
31+
func WithOnDiscoveryDevices(f func(*net.Request)) Option {
3232
return func(o *OptionsCfg) {
3333
if f != nil {
3434
o.onDiscoveryDevices = f

bridge/service/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *Service) handleDiscoverAllLinks(req *net.Request) (*pool.Message, error
8181
// discovery is only allowed for CON, NON, UNSET messages
8282
c.onDiscoveryDevices(req)
8383
}
84-
res := discovery.New(plgdResources.ResourceURI, func(request *net.Request) schema.ResourceLinks {
84+
res := discovery.New(plgdResources.ResourceURI, func(*net.Request) schema.ResourceLinks {
8585
links := make(schema.ResourceLinks, 0, c.devices.Length()+1)
8686
for _, d := range c.devices.CopyData() {
8787
dlinks := d.GetLinks(req)
@@ -128,7 +128,7 @@ func New(cfg Config, opts ...Option) (*Service, error) {
128128
}
129129

130130
o := OptionsCfg{
131-
onDiscoveryDevices: func(req *net.Request) {
131+
onDiscoveryDevices: func(*net.Request) {
132132
// nothing to do
133133
},
134134
logger: log.NewNilLogger(),

bridge/test/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewBridgedDeviceWithConfig(t *testing.T, s *service.Service, cfg device.Con
7373
}, false)
7474
deviceOpts := []device.Option{
7575
device.WithCAPool(caPool),
76-
device.WithGetCertificates(func(deviceID string) []tls.Certificate {
76+
device.WithGetCertificates(func(string) []tls.Certificate {
7777
return []tls.Certificate{test.GetMfgCertificate(t)}
7878
}),
7979
device.WithLogger(device.NewLogger(di, log.LevelDebug)),

client/core/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func DefaultDiscoveryConfiguration() DiscoveryConfiguration {
155155
MulticastHopLimit: 0, // will be set to 1 or 255 based on address
156156
MulticastAddressUDP4: DiscoveryAddressUDP4,
157157
MulticastAddressUDP6: DiscoveryAddressUDP6,
158-
MulticastOptions: []coapNet.MulticastOption{coapNet.WithMulticastInterfaceError(func(iface *net.Interface, err error) {
158+
MulticastOptions: []coapNet.MulticastOption{coapNet.WithMulticastInterfaceError(func(*net.Interface, error) {
159159
// ignore error
160160
})},
161161
}

client/core/client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func NewTestSecureClientWithCert(cert tls.Certificate, disableDTLS, disableTCPTL
7676

7777
var manOpts []manufacturer.OptionFunc
7878
if disableDTLS {
79-
manOpts = append(manOpts, manufacturer.WithDialDTLS(func(ctx context.Context, addr string, dtlsCfg *dtls.Config, opts ...udp.Option) (*coap.ClientCloseHandler, error) {
79+
manOpts = append(manOpts, manufacturer.WithDialDTLS(func(context.Context, string, *dtls.Config, ...udp.Option) (*coap.ClientCloseHandler, error) {
8080
return nil, pkgError.NotSupported()
8181
}))
8282
}
8383
if disableTCPTLS {
84-
manOpts = append(manOpts, manufacturer.WithDialTLS(func(ctx context.Context, addr string, tlsCfg *tls.Config, opts ...tcp.Option) (*coap.ClientCloseHandler, error) {
84+
manOpts = append(manOpts, manufacturer.WithDialTLS(func(context.Context, string, *tls.Config, ...tcp.Option) (*coap.ClientCloseHandler, error) {
8585
return nil, pkgError.NotSupported()
8686
}))
8787
}
@@ -91,12 +91,12 @@ func NewTestSecureClientWithCert(cert tls.Certificate, disableDTLS, disableTCPTL
9191

9292
var opts []core.OptionFunc
9393
if disableDTLS {
94-
opts = append(opts, core.WithDialDTLS(func(ctx context.Context, addr string, dtlsCfg *dtls.Config, opts ...udp.Option) (*coap.ClientCloseHandler, error) {
94+
opts = append(opts, core.WithDialDTLS(func(context.Context, string, *dtls.Config, ...udp.Option) (*coap.ClientCloseHandler, error) {
9595
return nil, pkgError.NotSupported()
9696
}))
9797
}
9898
if disableTCPTLS {
99-
opts = append(opts, core.WithDialTLS(func(ctx context.Context, addr string, tlsCfg *tls.Config, opts ...tcp.Option) (*coap.ClientCloseHandler, error) {
99+
opts = append(opts, core.WithDialTLS(func(context.Context, string, *tls.Config, ...tcp.Option) (*coap.ClientCloseHandler, error) {
100100
return nil, pkgError.NotSupported()
101101
}))
102102
}

client/core/device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func (d *Device) connectToEndpoint(ctx context.Context, endpoint schema.Endpoint
321321
return net.Addr{}, nil, MakeInternal(fmt.Errorf(errMsg, addr.URL(), err))
322322
}
323323
if !loaded {
324-
cc.RegisterCloseHandler(func(err error) {
324+
cc.RegisterCloseHandler(func(error) {
325325
d.removeConn(addr.URL(), conn)
326326
})
327327
}

client/core/observeResource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (d *Device) StopObservingResource(
8888

8989
func (d *Device) closeObservations(ctx context.Context) error {
9090
obs := make([]string, 0, 12)
91-
d.observations.Range(func(key string, value *observation) bool {
91+
d.observations.Range(func(key string, _ *observation) bool {
9292
observationID := key
9393
obs = append(obs, observationID)
9494
return false

client/core/ownDevice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func getDTLSClient(ctx context.Context, psk []byte, sdkID, addr string, oc otm.C
479479
idBin, _ := id.MarshalBinary()
480480
dtlsConfig := dtls.Config{
481481
PSKIdentityHint: idBin,
482-
PSK: func(b []byte) ([]byte, error) {
482+
PSK: func([]byte) ([]byte, error) {
483483
return psk, nil
484484
},
485485
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256},

client/core/ownDevice_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TestClientOwnDeviceWithFailSetupCertificates(t *testing.T) {
195195
require.NoError(t, err)
196196
links, err := dev.GetResourceLinks(ctx, dev.GetEndpoints())
197197
require.NoError(t, err)
198-
err = dev.Own(ctx, links, []otm.Client{justworks.NewClient()}, core.WithSetupCertificates(func(ctx context.Context, csr []byte) ([]byte, error) {
198+
err = dev.Own(ctx, links, []otm.Client{justworks.NewClient()}, core.WithSetupCertificates(func(context.Context, []byte) ([]byte, error) {
199199
return nil, fmt.Errorf("invalid")
200200
}))
201201
require.Error(t, err)

client/core/provisionDevice_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func TestSettingCloudResource(t *testing.T) {
126126
AuthorizationProvider: "testAuthorizationProvider",
127127
URL: "testURL",
128128
AuthorizationCode: "testAuthorizationCode",
129+
CloudID: "00000000-0000-0000-0000-000000000000",
129130
}
130131
err = pc.SetCloudResource(context.Background(), r)
131132
require.NoError(t, err)

client/deleteDevices_internal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func TestClientDeleteDevice(t *testing.T) {
246246
require.NoError(t, err)
247247
return context.WithValue(ctx, &ctxValueKeyMockHandler, h)
248248
},
249-
cleanUp: func(ctx context.Context, t *testing.T, c *Client, deviceID string) {
249+
cleanUp: func(ctx context.Context, t *testing.T, _ *Client, _ string) {
250250
h := ctx.Value(&ctxValueKeyMockHandler).(*mockObservationHandler)
251251
err := h.waitForClose(ctx)
252252
require.NoError(t, err)
@@ -281,7 +281,7 @@ func TestClientDeleteDevice(t *testing.T) {
281281
test.CheckResourceLinks(t, test.DefaultDevsimResourceLinks(), e)
282282
return context.WithValue(ctx, &ctxValueKeyMockHandler, h)
283283
},
284-
cleanUp: func(ctx context.Context, t *testing.T, c *Client, deviceID string) {
284+
cleanUp: func(ctx context.Context, t *testing.T, _ *Client, _ string) {
285285
h := ctx.Value(&ctxValueKeyMockHandler).(*mockDeviceResourcesObservationHandler)
286286
err := h.waitForClose(ctx)
287287
require.NoError(t, err)
@@ -305,7 +305,7 @@ func TestClientDeleteDevice(t *testing.T) {
305305
{
306306
name: "delete device added by ip",
307307
args: args{
308-
addDevice: func(ctx context.Context, t *testing.T, c *Client, deviceID string) context.Context {
308+
addDevice: func(ctx context.Context, t *testing.T, c *Client, _ string) context.Context {
309309
_, _, err := c.GetDeviceByIP(ctx, ip)
310310
require.NoError(t, err)
311311
return ctx

client/deviceCache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (c *DeviceCache) GetDevice(deviceID string) (*core.Device, bool) {
8989
func (c *DeviceCache) GetDeviceByFoundIP(ip string) []*core.Device {
9090
var d []*core.Device
9191
now := time.Now()
92-
c.devicesCache.Range(func(deviceID string, item *cache.Element[*core.Device]) bool {
92+
c.devicesCache.Range(func(_ string, item *cache.Element[*core.Device]) bool {
9393
if item.IsExpired(now) {
9494
return true
9595
}
@@ -178,7 +178,7 @@ func (c *DeviceCache) updateOrStoreDevice(device *core.Device, expiration time.T
178178
func (c *DeviceCache) GetDevicesFoundByIP() map[string]string {
179179
devices := make(map[string]string)
180180
now := time.Now()
181-
c.devicesCache.Range(func(deviceID string, item *cache.Element[*core.Device]) bool {
181+
c.devicesCache.Range(func(_ string, item *cache.Element[*core.Device]) bool {
182182
if item.IsExpired(now) {
183183
return true
184184
}

client/observeDevices.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (o *devicesObserver) poll(ctx context.Context) bool {
105105

106106
func (o *devicesObserver) processDevices(devices *coapSync.Map[string, struct{}]) (added map[string]struct{}, removed []string, current map[string]uint8) {
107107
current = make(map[string]uint8)
108-
devices.Range(func(key string, value struct{}) bool {
108+
devices.Range(func(key string, _ struct{}) bool {
109109
current[key] = 0
110110
return true
111111
})

client/observeResource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (o *observationsHandler) Handle(ctx context.Context, body coap.DecodeFunc)
314314
}
315315
decode := createDecodeFunc(message)
316316
o.lastMessage.Store(decode)
317-
o.observations.Range(func(key string, h *observationHandler) bool {
317+
o.observations.Range(func(_ string, h *observationHandler) bool {
318318
h.HandleMessage(ctx, decode)
319319
return true
320320
})

client/onboardDevice_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestClientOnboardDevice(t *testing.T) {
4747
authorizationProvider: "authorizationProvider",
4848
authorizationCode: "authorizationCode",
4949
cloudURL: "coaps+tcp://test:5684",
50-
cloudID: "cloudID",
50+
cloudID: "12e02711-b12e-42c9-b83f-784932ad066e",
5151
},
5252
},
5353
{
@@ -57,7 +57,7 @@ func TestClientOnboardDevice(t *testing.T) {
5757
authorizationProvider: "authorizationProvider",
5858
authorizationCode: "authorizationCode",
5959
cloudURL: "coaps+tcp://test:5684",
60-
cloudID: "cloudID",
60+
cloudID: "12e02711-b12e-42c9-b83f-784932ad066e",
6161
},
6262
wantErr: true,
6363
},

cmd/bridge-device/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func addResources(d service.Device, numResources int) {
8686
}
8787
go func() {
8888
for range time.After(time.Millisecond * 500) {
89-
obsWatcher.Range(func(key uint64, h func()) bool {
89+
obsWatcher.Range(func(_ uint64, h func()) bool {
9090
h()
9191
return true
9292
})

pkg/net/coap/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func DialTCP(ctx context.Context, addr string, opts ...tcp.Option) (*ClientClose
401401
}
402402

403403
func NewVerifyPeerCertificate(rootCAs *x509.CertPool, verifyPeerCertificate func(verifyPeerCertificate *x509.Certificate) error) func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
404-
return func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
404+
return func(rawCerts [][]byte, _ [][]*x509.Certificate) error {
405405
if len(rawCerts) == 0 {
406406
return fmt.Errorf("empty certificates chain")
407407
}
@@ -438,7 +438,7 @@ func NewVerifyPeerCertificate(rootCAs *x509.CertPool, verifyPeerCertificate func
438438

439439
func getDefaultTCPOptions(ctx context.Context, tlsCfg *tls.Config) []tcp.Option {
440440
dopts := make([]tcp.Option, 0, 4)
441-
dopts = append(dopts, options.WithErrors(func(err error) {
441+
dopts = append(dopts, options.WithErrors(func(error) {
442442
// ignore by default
443443
}), options.WithMessagePool(pool.New(0, 0)))
444444
if tlsCfg != nil {
@@ -470,7 +470,7 @@ func DialTCPSecure(ctx context.Context, addr string, tlsCfg *tls.Config, opts ..
470470

471471
func getDefaultUDPOptions(ctx context.Context) []udp.Option {
472472
dopts := make([]udp.Option, 0, 4)
473-
dopts = append(dopts, options.WithErrors(func(err error) {
473+
dopts = append(dopts, options.WithErrors(func(error) {
474474
// ignore by default
475475
}), options.WithMessagePool(pool.New(0, 0)))
476476
deadline, ok := ctx.Deadline()

schema/cloud/configuration.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ type Configuration struct {
5050

5151
// ConfigurationUpdateRequest is used to update the Cloud Configuration Resource.
5252
type ConfigurationUpdateRequest struct {
53-
AuthorizationProvider string `json:"apn"`
53+
AuthorizationProvider string `json:"apn,omitempty"`
5454
URL string `json:"cis"`
55-
AuthorizationCode string `json:"at"`
56-
CloudID string `json:"sid"`
55+
AuthorizationCode string `json:"at,omitempty"`
56+
CloudID string `json:"sid,omitempty"`
5757
}

schema/credential/credential_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func testCredentialData(t *testing.T, checkData func(data interface{}, expected
5555
}
5656

5757
for _, tt := range tests {
58-
t.Run(tt.name, func(t *testing.T) {
58+
t.Run(tt.name, func(*testing.T) {
5959
checkData(tt.args.data, tt.want)
6060
})
6161
}

0 commit comments

Comments
 (0)