@@ -24,6 +24,7 @@ import (
24
24
25
25
"github.com/hashicorp/consul/api"
26
26
"github.com/stretchr/testify/require"
27
+ "gotest.tools/v3/assert"
27
28
28
29
"github.com/ystia/yorc/v4/events"
29
30
"github.com/ystia/yorc/v4/helper/consulutil"
@@ -368,3 +369,30 @@ func testUnregisterAction(t *testing.T, client *api.Client) {
368
369
require .NotNil (t , kvp , "kvp is nil" )
369
370
require .Equal (t , "true" , string (kvp .Value ), "unregisterFlag is not set to true" )
370
371
}
372
+
373
+ func testUpdateActionData (t * testing.T , client * api.Client ) {
374
+ t .Parallel ()
375
+ deploymentID := "dep-" + t .Name ()
376
+ ti := 1 * time .Second
377
+ actionType := "test-action"
378
+ action := & prov.Action {ActionType : actionType , Data : map [string ]string {"key1" : "val1" , "key2" : "val2" , "key3" : "val3" }}
379
+ id , err := scheduling .RegisterAction (client , deploymentID , ti , action )
380
+ assert .NilError (t , err , "Failed to register action" )
381
+
382
+ err = scheduling .UpdateActionData (client , id , "key2" , "newVal" )
383
+ assert .NilError (t , err , "Failed to update action data" )
384
+
385
+ testSched := scheduler {cc : client }
386
+ newAction , err := testSched .buildScheduledAction (id )
387
+ assert .NilError (t , err , "Failed to build action" )
388
+
389
+ val := newAction .Data ["key2" ]
390
+ assert .Equal (t , val , "newVal" , "Unexpected value for action key updated" )
391
+
392
+ // Check the update of an unregistered action, should fail
393
+ err = testSched .unregisterAction (id )
394
+ assert .NilError (t , err , "Failed to unregister action" )
395
+
396
+ err = scheduling .UpdateActionData (client , id , "key3" , "newVal" )
397
+ assert .ErrorContains (t , err , "unregistered" )
398
+ }
0 commit comments