Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lubo-kistler committed Nov 20, 2024
1 parent 4a9e9d7 commit 66d3ee4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
5 changes: 4 additions & 1 deletion client/createResource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ func TestClientCreateResource(t *testing.T) {
opts: []client.CreateOption{
client.WithDiscoveryConfiguration(core.DefaultDiscoveryConfiguration()),
client.WithLinkNotFoundCallback(func(links schema.ResourceLinks, href string) (schema.ResourceLink, error) {
resourceLink, _ := links.GetResourceLink(test.TestResourceSwitchesHref)
_, linkFound := links.GetResourceLink(href)
require.False(t, linkFound)
resourceLink, linkFound := links.GetResourceLink(test.TestResourceSwitchesHref)
require.True(t, linkFound)
return resourceLink, nil
}),
},
Expand Down
5 changes: 4 additions & 1 deletion client/getResource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ func TestClientGetResource(t *testing.T) {
// as the only thing that we need in the link is the href and endpoints we will reuse
// some known discoverable resource
client.WithLinkNotFoundCallback(func(links schema.ResourceLinks, href string) (schema.ResourceLink, error) {
resourceLink, _ := links.GetResourceLink(configuration.ResourceURI)
resourceLink, ok := links.GetResourceLink(configuration.ResourceURI)
if !ok {
return schema.ResourceLink{}, fmt.Errorf("failed to get resource link: %w", err)
}
resourceLink.Href = href
return resourceLink, nil
}),
Expand Down
13 changes: 8 additions & 5 deletions client/observeResource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ func TestObservingResource(t *testing.T) {

func TestObservingNonDiscoverableResource(t *testing.T) {
testDevice(t, test.DevsimName, func(ctx context.Context, t *testing.T, c *client.Client, deviceID string) {

// link not found callback
linkNotFoundCallback := func(links schema.ResourceLinks, href string) (schema.ResourceLink, error) {
// as the resource in not discoverable, we need to provide the link with the correct href
Expand All @@ -182,6 +181,10 @@ func TestObservingNonDiscoverableResource(t *testing.T) {
var got map[string]interface{}
err := c.CreateResource(ctx, deviceID, test.TestResourceSwitchesHref, test.MakeNonDiscoverableSwitchData(), &got)
require.NoError(t, err)
defer func() {
errCleanup := c.DeleteResource(ctx, deviceID, test.TestResourceSwitchesInstanceHref("1"), nil, client.WithLinkNotFoundCallback(linkNotFoundCallback))
require.NoError(t, errCleanup)
}()
// remove the instance parameter as the number is assigned by the device and we can't predict its value
delete(got, "ins")
require.Equal(t, test.MakeSwitchResourceData(map[string]interface{}{
Expand Down Expand Up @@ -211,7 +214,7 @@ func TestObservingNonDiscoverableResource(t *testing.T) {
response := coap.DetailedResponse[map[string]interface{}]{}
err = responseDecoder(&response)
require.NoError(t, err)
require.Equal(t, false, response.Body["value"].(bool))
require.False(t, response.Body["value"].(bool))

// change the value of the switch and wait for the observation notification
err = c.UpdateResource(ctx, deviceID, test.TestResourceSwitchesInstanceHref("1"), map[string]interface{}{
Expand All @@ -221,18 +224,18 @@ func TestObservingNonDiscoverableResource(t *testing.T) {

defer func() {
// restore to original value
err := c.UpdateResource(ctx, deviceID, test.TestResourceSwitchesInstanceHref("1"), map[string]interface{}{
errRestore := c.UpdateResource(ctx, deviceID, test.TestResourceSwitchesInstanceHref("1"), map[string]interface{}{
"value": false,
}, nil, client.WithLinkNotFoundCallback(linkNotFoundCallback))
require.NoError(t, err)
require.NoError(t, errRestore)
}()

// second notification contains the new value
responseDecoder, err = observation.WaitForNotification(ctx)
require.NoError(t, err)
err = responseDecoder(&response)
require.NoError(t, err)
require.Equal(t, true, response.Body["value"].(bool))
require.True(t, response.Body["value"].(bool))
})
}

Expand Down
10 changes: 5 additions & 5 deletions client/options_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestApplyOnGet(t *testing.T) {
}
etag := "123"
codec := ocf.VNDOCFCBORCodec{}
linkNotFoundCallback := func(links schema.ResourceLinks, href string) (schema.ResourceLink, error) {
linkNotFoundCallback := func(_ schema.ResourceLinks, href string) (schema.ResourceLink, error) {
return schema.ResourceLink{Href: href}, nil
}
opts := []GetOption{
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestApplyOnObserve(t *testing.T) {
MulticastHopLimit: 42,
}
codec := ocf.VNDOCFCBORCodec{}
linkNotFoundCallback := func(links schema.ResourceLinks, href string) (schema.ResourceLink, error) {
linkNotFoundCallback := func(_ schema.ResourceLinks, href string) (schema.ResourceLink, error) {
return schema.ResourceLink{Href: href}, nil
}

Expand Down Expand Up @@ -181,7 +181,7 @@ func TestApplyOnUpdate(t *testing.T) {
MulticastHopLimit: 42,
}
codec := ocf.VNDOCFCBORCodec{}
linkNotFoundCallback := func(links schema.ResourceLinks, href string) (schema.ResourceLink, error) {
linkNotFoundCallback := func(_ schema.ResourceLinks, href string) (schema.ResourceLink, error) {
return schema.ResourceLink{Href: href}, nil
}
opts := []UpdateOption{
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestApplyOnCreate(t *testing.T) {
MulticastHopLimit: 42,
}
codec := ocf.VNDOCFCBORCodec{}
linkNotFoundCallback := func(links schema.ResourceLinks, href string) (schema.ResourceLink, error) {
linkNotFoundCallback := func(_ schema.ResourceLinks, href string) (schema.ResourceLink, error) {
return schema.ResourceLink{Href: href}, nil
}
opts := []CreateOption{
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestApplyOnDelete(t *testing.T) {
MulticastHopLimit: 42,
}
codec := ocf.VNDOCFCBORCodec{}
linkNotFoundCallback := func(links schema.ResourceLinks, href string) (schema.ResourceLink, error) {
linkNotFoundCallback := func(_ schema.ResourceLinks, href string) (schema.ResourceLink, error) {
return schema.ResourceLink{Href: href}, nil
}
opts := []DeleteOption{
Expand Down

0 comments on commit 66d3ee4

Please sign in to comment.