@@ -24,6 +24,7 @@ import (
2424 "github.com/plgd-dev/device/v2/client"
2525 "github.com/plgd-dev/device/v2/client/core"
2626 "github.com/plgd-dev/device/v2/schema"
27+ "github.com/plgd-dev/device/v2/schema/configuration"
2728 "github.com/plgd-dev/device/v2/schema/device"
2829 "github.com/plgd-dev/device/v2/schema/interfaces"
2930 "github.com/plgd-dev/device/v2/schema/resources"
@@ -52,7 +53,28 @@ func createSwitches(ctx context.Context, t *testing.T, c *client.Client, deviceI
5253
5354func TestClientDeleteResource (t * testing.T ) {
5455 deviceID := test .MustFindDeviceByName (test .DevsimName )
55- const switchID = "1"
56+ const (
57+ switchID_1 = "1"
58+ switchID_2 = "2"
59+ )
60+
61+ c , err := testClient .NewTestSecureClient ()
62+ require .NoError (t , err )
63+ defer func () {
64+ errC := c .Close (context .Background ())
65+ require .NoError (t , errC )
66+ }()
67+ ctx , cancel := context .WithTimeout (context .Background (), test .TestTimeout )
68+ defer cancel ()
69+ deviceID , err = c .OwnDevice (ctx , deviceID , client .WithOTMs ([]client.OTMType {client .OTMType_JustWorks }))
70+ require .NoError (t , err )
71+ defer disown (t , c , deviceID )
72+
73+ createSwitches (ctx , t , c , deviceID , 2 )
74+ var nonDiscoverableResource map [string ]interface {}
75+ err = c .CreateResource (ctx , deviceID , test .TestResourceSwitchesHref , test .MakeNonDiscoverableSwitchData (), & nonDiscoverableResource )
76+ require .NoError (t , err )
77+
5678 type args struct {
5779 deviceID string
5880 href string
@@ -67,10 +89,28 @@ func TestClientDeleteResource(t *testing.T) {
6789 name : "valid" ,
6890 args : args {
6991 deviceID : deviceID ,
70- href : test .TestResourceSwitchesInstanceHref (switchID ),
92+ href : test .TestResourceSwitchesInstanceHref (switchID_1 ),
7193 opts : []client.DeleteOption {client .WithDiscoveryConfiguration (core .DefaultDiscoveryConfiguration ())},
7294 },
7395 },
96+ {
97+ name : "delete non-discoverable resource" ,
98+ args : args {
99+ deviceID : deviceID ,
100+ href : nonDiscoverableResource ["href" ].(string ),
101+ opts : []client.DeleteOption {
102+ client .WithDiscoveryConfiguration (core .DefaultDiscoveryConfiguration ()),
103+ // create the link for non-discoverable resource by utilizing the linkNotFoundCallback
104+ // as the only thing that we need in the link is the href and endpoints we will reuse
105+ // some known discoverable resource
106+ client .WithLinkNotFoundCallback (func (links schema.ResourceLinks , href string ) (schema.ResourceLink , error ) {
107+ resourceLink , _ := links .GetResourceLink (configuration .ResourceURI )
108+ resourceLink .Href = href
109+ return resourceLink , nil
110+ }),
111+ },
112+ },
113+ },
74114 {
75115 name : "invalid href" ,
76116 args : args {
@@ -89,20 +129,6 @@ func TestClientDeleteResource(t *testing.T) {
89129 },
90130 }
91131
92- c , err := testClient .NewTestSecureClient ()
93- require .NoError (t , err )
94- defer func () {
95- errC := c .Close (context .Background ())
96- require .NoError (t , errC )
97- }()
98- ctx , cancel := context .WithTimeout (context .Background (), test .TestTimeout )
99- defer cancel ()
100- deviceID , err = c .OwnDevice (ctx , deviceID , client .WithOTMs ([]client.OTMType {client .OTMType_JustWorks }))
101- require .NoError (t , err )
102- defer disown (t , c , deviceID )
103-
104- createSwitches (ctx , t , c , deviceID , 1 )
105-
106132 for _ , tt := range tests {
107133 t .Run (tt .name , func (t * testing.T ) {
108134 err := c .DeleteResource (ctx , tt .args .deviceID , tt .args .href , nil , tt .args .opts ... )
0 commit comments