From f86cd7e84f0503ef904ec85668b24fdc0c7de8f7 Mon Sep 17 00:00:00 2001 From: MIRIAM-SLOV <168483221+MIRIAM-SLOV@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:15:00 +0300 Subject: [PATCH] fix tags with tag-prefix (#549) * fix tags with tag-prefix * new UT --------- Co-authored-by: ChanochShayner <57212002+ChanochShayner@users.noreply.github.com> --- src/common/tagging/tag_group.go | 2 +- src/common/tagging/tag_group_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/common/tagging/tag_group.go b/src/common/tagging/tag_group.go index bc9a67cf..3509e377 100644 --- a/src/common/tagging/tag_group.go +++ b/src/common/tagging/tag_group.go @@ -49,7 +49,7 @@ func (t *TagGroup) SetTags(tags []tags.ITag) { for _, tag := range tags { tag.Init() tag.SetTagPrefix(t.Options.TagPrefix) - if !t.IsTagSkipped(tag) && (t.SpecifiedTags == nil || len(t.SpecifiedTags) == 0 || utils.InSlice(t.SpecifiedTags, tag.GetKey())) { + if !t.IsTagSkipped(tag) && (t.SpecifiedTags == nil || len(t.SpecifiedTags) == 0 || utils.InSlice(t.SpecifiedTags, strings.TrimPrefix(tag.GetKey(), t.Options.TagPrefix))) { t.tags = append(t.tags, tag) } } diff --git a/src/common/tagging/tag_group_test.go b/src/common/tagging/tag_group_test.go index f2723aa3..c8f6f486 100644 --- a/src/common/tagging/tag_group_test.go +++ b/src/common/tagging/tag_group_test.go @@ -52,4 +52,20 @@ func TestTagGroup(t *testing.T) { tgs := tagGroup.GetTags() assert.Equal(t, 0, len(tgs)) }) + + t.Run("Test tag prefix not broke tags", func(t *testing.T) { + tagGroup := TagGroup{Options: InitTagGroupOptions{ + TagPrefix: "prefix_", + }, + SpecifiedTags: []string{"yor_trace"}, + } + tagGroup.SetTags([]tags.ITag{ + &tags.Tag{Key: "yor_trace"}, + &tags.Tag{Key: "git_modifiers"}, + }) + tgs := tagGroup.GetTags() + assert.Equal(t, 1, len(tgs)) + assert.Equal(t, string("prefix_yor_trace"), tgs[0].GetKey()) + + }) }