From 31645722dbc6cfc0c99fd7a86d2284db698c97b8 Mon Sep 17 00:00:00 2001 From: Jack Chen Date: Wed, 30 Oct 2024 11:17:04 +0800 Subject: [PATCH] fix: Fix missing tags issue in FilterByResourceName func fixes #1627 Signed-off-by: Jack Chen --- pkg/transforms/filter.go | 1 + pkg/transforms/filter_test.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/pkg/transforms/filter.go b/pkg/transforms/filter.go index 635b3f4f7..388ce53fb 100755 --- a/pkg/transforms/filter.go +++ b/pkg/transforms/filter.go @@ -121,6 +121,7 @@ func (f *Filter) FilterByResourceName(ctx interfaces.AppFunctionContext, data in auxEvent.Id = existingEvent.Id auxEvent.Origin = existingEvent.Origin auxEvent.Readings = []dtos.BaseReading{} + auxEvent.Tags = existingEvent.Tags if f.FilterOut { for _, reading := range existingEvent.Readings { diff --git a/pkg/transforms/filter_test.go b/pkg/transforms/filter_test.go index db98705b8..91cccf4f2 100644 --- a/pkg/transforms/filter_test.go +++ b/pkg/transforms/filter_test.go @@ -208,6 +208,8 @@ func TestFilter_FilterByResourceName(t *testing.T) { // event with a reading for resource 1 resource1Event := dtos.NewEvent(profileName1, deviceName1, sourceName1) err := resource1Event.AddSimpleReading(resource1, common.ValueTypeInt32, int32(123)) + // add tags to the event for testing + resource1Event.Tags = map[string]any{"tag1": "value1"} require.NoError(t, err) // event with a reading for resource 2 @@ -296,6 +298,11 @@ func TestFilter_FilterByResourceName(t *testing.T) { request := requests.NewAddEventRequest(actualEvent) err = request.Validate() require.NoError(t, err) + + // Make sure the tags are still there + if test.EventIn.Tags != nil { + assert.Equal(t, test.EventIn.Tags, actualEvent.Tags) + } } } })