Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit d4b8f61

Browse files
c3dfidencio
authored andcommitted
annotations: Add unit test for checkPathIsInGlobs
There are a few interesting corner cases to consider for this function. Fixes: #3004 Suggested-by: James O.D. Hunt <[email protected]> Signed-off-by: Christophe de Dinechin <[email protected]>
1 parent 9b733a9 commit d4b8f61

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

virtcontainers/pkg/oci/utils_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,3 +982,34 @@ func TestRegexpContains(t *testing.T) {
982982
assert.Equal(d.expected, matched, "%+v", d)
983983
}
984984
}
985+
986+
func TestCheckPathIsInGlobs(t *testing.T) {
987+
assert := assert.New(t)
988+
989+
type testData struct {
990+
globs []string
991+
toMatch string
992+
expected bool
993+
}
994+
995+
data := []testData{
996+
{[]string{}, "", false},
997+
{[]string{}, "nonempty", false},
998+
{[]string{"simple"}, "simple", false},
999+
{[]string{"simple"}, "some_simple_text", false},
1000+
{[]string{"/bin/ls"}, "/bin/ls", true},
1001+
{[]string{"/bin/ls", "/bin/false"}, "/bin/ls", true},
1002+
{[]string{"/bin/ls", "/bin/false"}, "/bin/false", true},
1003+
{[]string{"/bin/ls", "/bin/false"}, "/bin/bar", false},
1004+
{[]string{"/bin/*ls*"}, "/bin/ls", true},
1005+
{[]string{"/bin/*ls*"}, "/bin/false", true},
1006+
{[]string{"bin/ls"}, "/bin/ls", false},
1007+
{[]string{"./bin/ls"}, "/bin/ls", false},
1008+
{[]string{"*/bin/ls"}, "/bin/ls", false},
1009+
}
1010+
1011+
for _, d := range data {
1012+
matched := checkPathIsInGlobs(d.globs, d.toMatch)
1013+
assert.Equal(d.expected, matched, "%+v", d)
1014+
}
1015+
}

0 commit comments

Comments
 (0)