Skip to content

Commit

Permalink
Add terraform scope. Update test to use a table to verify known scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhas Vishwanath committed Feb 21, 2022
1 parent 0a7dc31 commit 80d51b1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 36 deletions.
9 changes: 5 additions & 4 deletions talismanrc/scopes.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package talismanrc

var knownScopes = map[string][]string{
"node": {"yarn.lock", "package-lock.json", "node_modules/"},
"go": {"makefile", "go.mod", "go.sum", "Gopkg.toml", "Gopkg.lock", "glide.yaml", "glide.lock", "vendor/"},
"images": {"*.jpeg", "*.jpg", "*.png", "*.tiff", "*.bmp"},
"bazel": {"*.bzl"},
"node": {"yarn.lock", "package-lock.json", "node_modules/"},
"go": {"makefile", "go.mod", "go.sum", "Gopkg.toml", "Gopkg.lock", "glide.yaml", "glide.lock", "vendor/"},
"images": {"*.jpeg", "*.jpg", "*.png", "*.tiff", "*.bmp"},
"bazel": {"*.bzl"},
"terraform": {".terraform.lock.hcl"},
}
70 changes: 38 additions & 32 deletions talismanrc/talismanrc_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package talismanrc

import (
"fmt"
"io/ioutil"
"os"
"testing"
Expand Down Expand Up @@ -60,38 +61,43 @@ func TestDirectoryPatterns(t *testing.T) {
}

func TestIgnoreAdditionsByScope(t *testing.T) {
file1 := testAddition("yarn.lock")
file2 := testAddition("similaryarn.lock")
file3 := testAddition("java.lock")
file4 := testAddition("Gopkg.lock")
file5 := testAddition("vendors/abc")
file6 := testAddition("imgJpeg.jpeg")
file7 := testAddition("imgJpg.jpg")
file8 := testAddition("imgPng.png")
file9 := testAddition("build.bzl")
additions := []gitrepo.Addition{file1, file2, file3, file4, file5, file6, file7, file8, file9}

scopesToIgnore := []string{"node", "go", "images", "bazel"}
talismanRCConfig := createTalismanRCWithScopeIgnores(scopesToIgnore)

nodeIgnores := []string{"node.lock", "*yarn.lock"}
javaIgnores := []string{"java.lock"}
goIgnores := []string{"go.lock", "Gopkg.lock", "vendors/"}
imageIgnores := []string{"*.jpeg", "*.jpg", "*.png"}
bazelIgnores := []string{"*.bzl"}
scopesMap := map[string][]string{"node": nodeIgnores, "java": javaIgnores, "go": goIgnores, "images": imageIgnores, "bazel": bazelIgnores}
knownScopes = scopesMap
filteredAdditions := talismanRCConfig.FilterAdditions(additions)

assert.NotContains(t, filteredAdditions, file1)
assert.NotContains(t, filteredAdditions, file2)
assert.Contains(t, filteredAdditions, file3)
assert.NotContains(t, filteredAdditions, file4)
assert.NotContains(t, filteredAdditions, file5)
assert.NotContains(t, filteredAdditions, file6)
assert.NotContains(t, filteredAdditions, file7)
assert.NotContains(t, filteredAdditions, file8)
assert.NotContains(t, filteredAdditions, file9)
testTable := map[string][]gitrepo.Addition{
"node": {
testAddition("yarn.lock"),
testAddition("package-lock.json"),
testAddition("node_modules/module1/foo.js")},
"go": {
testAddition("Gopkg.lock"),
testAddition("makefile"),
testAddition("go.mod"), testAddition("go.sum"),
testAddition("Gopkg.toml"), testAddition("Gopkg.lock"),
testAddition("glide.yaml"), testAddition("glide.lock"),
testAddition("vendor/abc"), testAddition("vendor/foo/def"),
},
"images": {
testAddition("img.jpeg"),
testAddition("img.jpg"),
testAddition("img.png"),
testAddition("img.tiff"),
testAddition("img.bmp"),
},
"bazel": {testAddition("bazelfile.bzl")},
"terraform": {
testAddition(".terraform.lock.hcl"),
testAddition("foo/.terraform.lock.hcl"),
testAddition("foo/bar/.terraform.lock.hcl"),
},
}

for scopeName, additions := range testTable {
t.Run(fmt.Sprintf("should ignore files for %s scope", scopeName), func(t *testing.T) {
talismanRCConfig := createTalismanRCWithScopeIgnores([]string{scopeName})
filteredAdditions := talismanRCConfig.FilterAdditions(additions)
for _, addition := range additions {
assert.NotContains(t, filteredAdditions, addition, "Expected %s to be ignored", addition.Name)
}
})
}
}

func TestIgnoringDetectors(t *testing.T) {
Expand Down

0 comments on commit 80d51b1

Please sign in to comment.