diff --git a/models/schedulejob.go b/models/schedulejob.go index 5a6461ea..b529ec61 100644 --- a/models/schedulejob.go +++ b/models/schedulejob.go @@ -134,8 +134,8 @@ func (c CronScheduleDef) GetBaseScheduleDef() BaseScheduleDef { type ScheduleAction interface { GetBaseScheduleAction() BaseScheduleAction - // WithEmptyPayload returns a copy of the ScheduleAction with empty payload, which is used by ScheduleActionRecord to remove the payload before storing the record into database - WithEmptyPayload() ScheduleAction + // WithEmptyPayloadAndId returns a copy of the ScheduleAction with empty payload and Id, which is used by ScheduleActionRecord to remove the payload and id before storing the record into database + WithEmptyPayloadAndId() ScheduleAction // WithId returns a copy of the ScheduleAction with ID or generates a new ID if the ID is empty, which is used to identify the action and record in the database WithId() ScheduleAction } @@ -197,7 +197,8 @@ type EdgeXMessageBusAction struct { func (m EdgeXMessageBusAction) GetBaseScheduleAction() BaseScheduleAction { return m.BaseScheduleAction } -func (m EdgeXMessageBusAction) WithEmptyPayload() ScheduleAction { +func (m EdgeXMessageBusAction) WithEmptyPayloadAndId() ScheduleAction { + m.Id = "" m.Payload = nil return m } @@ -218,7 +219,8 @@ type RESTAction struct { func (r RESTAction) GetBaseScheduleAction() BaseScheduleAction { return r.BaseScheduleAction } -func (r RESTAction) WithEmptyPayload() ScheduleAction { +func (r RESTAction) WithEmptyPayloadAndId() ScheduleAction { + r.Id = "" r.Payload = nil return r } @@ -238,7 +240,8 @@ type DeviceControlAction struct { func (d DeviceControlAction) GetBaseScheduleAction() BaseScheduleAction { return d.BaseScheduleAction } -func (d DeviceControlAction) WithEmptyPayload() ScheduleAction { +func (d DeviceControlAction) WithEmptyPayloadAndId() ScheduleAction { + d.Id = "" d.Payload = nil return d } diff --git a/models/schedulejob_test.go b/models/schedulejob_test.go index 031a4246..78259a72 100644 --- a/models/schedulejob_test.go +++ b/models/schedulejob_test.go @@ -164,6 +164,7 @@ var scheduleJobWithInvalidScheduleAction = `{ var edgeXMessageBusAction = EdgeXMessageBusAction{ BaseScheduleAction: BaseScheduleAction{ + Id: ExampleUUID, Type: common.ActionEdgeXMessageBus, ContentType: TestContentType, Payload: []byte(TestPayload), @@ -173,6 +174,7 @@ var edgeXMessageBusAction = EdgeXMessageBusAction{ var restAction = RESTAction{ BaseScheduleAction: BaseScheduleAction{ + Id: ExampleUUID, Type: common.ActionREST, ContentType: TestContentType, Payload: []byte(TestPayload), @@ -182,6 +184,7 @@ var restAction = RESTAction{ var deviceControlAction = DeviceControlAction{ BaseScheduleAction: BaseScheduleAction{ + Id: ExampleUUID, Type: common.ActionDeviceControl, ContentType: TestContentType, Payload: []byte(TestPayload), @@ -317,20 +320,21 @@ func TestScheduleAction_GetBaseScheduleAction(t *testing.T) { } } -func TestScheduleAction_WithEmptyPayload(t *testing.T) { +func TestScheduleAction_WithEmptyPayloadAndId(t *testing.T) { tests := []struct { name string action ScheduleAction expected ScheduleAction }{ - {"EdgeXMessageBusAction", edgeXMessageBusAction, edgeXMessageBusAction.WithEmptyPayload()}, - {"RESTAction", restAction, restAction.WithEmptyPayload()}, - {"DeviceControlAction", deviceControlAction, deviceControlAction.WithEmptyPayload()}, + {"EdgeXMessageBusAction", edgeXMessageBusAction, edgeXMessageBusAction.WithEmptyPayloadAndId()}, + {"RESTAction", restAction, restAction.WithEmptyPayloadAndId()}, + {"DeviceControlAction", deviceControlAction, deviceControlAction.WithEmptyPayloadAndId()}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := tt.action.WithEmptyPayload() - assert.Nil(t, result.GetBaseScheduleAction().Payload, "WithEmptyPayload did not result in empty Payload.") + result := tt.action.WithEmptyPayloadAndId() + assert.Nil(t, result.GetBaseScheduleAction().Payload, "WithEmptyPayloadAndId did not result in empty Payload.") + assert.Equal(t, "", result.GetBaseScheduleAction().Id, "WithEmptyPayloadAndId did not result in empty Id.") }) } }