From 66d3ee4c80c34b14d6b9098e4b939c675c2b3845 Mon Sep 17 00:00:00 2001 From: cah Date: Wed, 20 Nov 2024 10:19:30 +0100 Subject: [PATCH] Fix linter issues --- client/createResource_test.go | 5 ++++- client/getResource_test.go | 5 ++++- client/observeResource_test.go | 13 ++++++++----- client/options_internal_test.go | 10 +++++----- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/client/createResource_test.go b/client/createResource_test.go index bf93b5cb..e507a5c0 100644 --- a/client/createResource_test.go +++ b/client/createResource_test.go @@ -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 }), }, diff --git a/client/getResource_test.go b/client/getResource_test.go index c6b1f88a..2f7d32dc 100644 --- a/client/getResource_test.go +++ b/client/getResource_test.go @@ -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 }), diff --git a/client/observeResource_test.go b/client/observeResource_test.go index c1c15e0a..777bff64 100644 --- a/client/observeResource_test.go +++ b/client/observeResource_test.go @@ -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 @@ -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{}{ @@ -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{}{ @@ -221,10 +224,10 @@ 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 @@ -232,7 +235,7 @@ func TestObservingNonDiscoverableResource(t *testing.T) { 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)) }) } diff --git a/client/options_internal_test.go b/client/options_internal_test.go index 51160236..1ab9e574 100644 --- a/client/options_internal_test.go +++ b/client/options_internal_test.go @@ -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{ @@ -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 } @@ -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{ @@ -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{ @@ -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{