@@ -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"
@@ -51,7 +52,28 @@ func createSwitches(ctx context.Context, t *testing.T, c *client.Client, deviceI
5152
5253func TestClientDeleteResource (t * testing.T ) {
5354 deviceID := test .MustFindDeviceByName (test .DevsimName )
54- const switchID = "1"
55+ const (
56+ switchID_1 = "1"
57+ switchID_2 = "2"
58+ )
59+
60+ c , err := NewTestSecureClient ()
61+ require .NoError (t , err )
62+ defer func () {
63+ errC := c .Close (context .Background ())
64+ require .NoError (t , errC )
65+ }()
66+ ctx , cancel := context .WithTimeout (context .Background (), TestTimeout )
67+ defer cancel ()
68+ deviceID , err = c .OwnDevice (ctx , deviceID , client .WithOTMs ([]client.OTMType {client .OTMType_JustWorks }))
69+ require .NoError (t , err )
70+ defer disown (t , c , deviceID )
71+
72+ createSwitches (ctx , t , c , deviceID , 2 )
73+ var nonDiscoverableResource map [string ]interface {}
74+ err = c .CreateResource (ctx , deviceID , test .TestResourceSwitchesHref , test .MakeNonDiscoverableSwitchData (), & nonDiscoverableResource )
75+ require .NoError (t , err )
76+
5577 type args struct {
5678 deviceID string
5779 href string
@@ -66,10 +88,28 @@ func TestClientDeleteResource(t *testing.T) {
6688 name : "valid" ,
6789 args : args {
6890 deviceID : deviceID ,
69- href : test .TestResourceSwitchesInstanceHref (switchID ),
91+ href : test .TestResourceSwitchesInstanceHref (switchID_1 ),
7092 opts : []client.DeleteOption {client .WithDiscoveryConfiguration (core .DefaultDiscoveryConfiguration ())},
7193 },
7294 },
95+ {
96+ name : "delete non-discoverable resource" ,
97+ args : args {
98+ deviceID : deviceID ,
99+ href : nonDiscoverableResource ["href" ].(string ),
100+ opts : []client.DeleteOption {
101+ client .WithDiscoveryConfiguration (core .DefaultDiscoveryConfiguration ()),
102+ // create the link for non-discoverable resource by utilizing the linkNotFoundCallback
103+ // as the only thing that we need in the link is the href and endpoints we will reuse
104+ // some known discoverable resource
105+ client .WithLinkNotFoundCallback (func (links schema.ResourceLinks , href string ) (schema.ResourceLink , error ) {
106+ resourceLink , _ := links .GetResourceLink (configuration .ResourceURI )
107+ resourceLink .Href = href
108+ return resourceLink , nil
109+ }),
110+ },
111+ },
112+ },
73113 {
74114 name : "invalid href" ,
75115 args : args {
@@ -88,20 +128,6 @@ func TestClientDeleteResource(t *testing.T) {
88128 },
89129 }
90130
91- c , err := NewTestSecureClient ()
92- require .NoError (t , err )
93- defer func () {
94- errC := c .Close (context .Background ())
95- require .NoError (t , errC )
96- }()
97- ctx , cancel := context .WithTimeout (context .Background (), TestTimeout )
98- defer cancel ()
99- deviceID , err = c .OwnDevice (ctx , deviceID , client .WithOTMs ([]client.OTMType {client .OTMType_JustWorks }))
100- require .NoError (t , err )
101- defer disown (t , c , deviceID )
102-
103- createSwitches (ctx , t , c , deviceID , 1 )
104-
105131 for _ , tt := range tests {
106132 t .Run (tt .name , func (t * testing.T ) {
107133 err := c .DeleteResource (ctx , tt .args .deviceID , tt .args .href , nil , tt .args .opts ... )
0 commit comments