From d838efa7bdc3878eeb33fbc2e8fb11c7b097e4a2 Mon Sep 17 00:00:00 2001 From: MIRIAM-SLOV Date: Tue, 16 Jul 2024 18:23:08 +0300 Subject: [PATCH] new UT --- src/common/tagging/tag_group_test.go | 16 ++++++++++++++++ tests/integration/integration_test.go | 8 +++----- 2 files changed, 19 insertions(+), 5 deletions(-) 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()) + + }) } diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 359eb386..41f6d5b8 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -201,7 +201,7 @@ func TestRunResults(t *testing.T) { } }) - t.Run("Test terraform-aws-bridgecrew-read-only tagging specified tags with tag-prefix", func(t *testing.T) { + t.Run("Test terraform-aws-bridgecrew-read-only tagging specified tags", func(t *testing.T) { repoPath := utils.CloneRepo("https://github.com/bridgecrewio/terraform-aws-bridgecrew-read-only.git", "a8686215642fd47a38bf8615d91d0d40630ab989") defer os.RemoveAll(repoPath) @@ -210,7 +210,6 @@ func TestRunResults(t *testing.T) { Directory: repoPath, TagGroups: getTagGroups(), Tag: []string{"yor_trace"}, - TagPrefix: "prefix_", Parsers: []string{"Terraform"}, }) failIfErr(t, err) @@ -221,11 +220,10 @@ func TestRunResults(t *testing.T) { report := reportService.GetReport() assert.LessOrEqual(t, 18, report.Summary.Scanned) assert.Greater(t, report.Summary.Scanned, 0) - assert.NotEqual(t, 0, len(report.NewResourceTags)) for _, newTag := range report.NewResourceTags { - if strings.HasPrefix(newTag.File, repoPath) { - assert.Equal(t, "prefix_yor_trace", newTag.TagKey) + if strings.HasPrefix(repoPath, newTag.File) { + assert.Equal(t, "yor_trace", newTag.TagKey) assert.Equal(t, "aws_iam_role.bridgecrew_account_role", newTag.ResourceID) } }