Skip to content

Commit

Permalink
new UT
Browse files Browse the repository at this point in the history
  • Loading branch information
MIRIAM-SLOV committed Jul 16, 2024
1 parent 7e1b085 commit d838efa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/common/tagging/tag_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

})
}
8 changes: 3 additions & 5 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)
}
}
Expand Down

0 comments on commit d838efa

Please sign in to comment.