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

Commit

Permalink
annotations: Add unit test for checkPathIsInGlobs
Browse files Browse the repository at this point in the history
There are a few interesting corner cases to consider for this
function.

Fixes: #3004

Suggested-by: James O.D. Hunt <james.o.hunt@intel.com>
Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
  • Loading branch information
c3d committed Nov 10, 2020
1 parent ad9ce3f commit 151e6fc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions virtcontainers/pkg/oci/utils_test.go
Expand Up @@ -982,3 +982,34 @@ func TestRegexpContains(t *testing.T) {
assert.Equal(d.expected, matched, "%+v", d)
}
}

func TestCheckPathIsInGlobs(t *testing.T) {
assert := assert.New(t)

type testData struct {
globs []string
toMatch string
expected bool
}

data := []testData{
{[]string{}, "", false},
{[]string{}, "nonempty", false},
{[]string{"simple"}, "simple", false},
{[]string{"simple"}, "some_simple_text", false},
{[]string{"/bin/ls"}, "/bin/ls", true},
{[]string{"/bin/ls", "/bin/false"}, "/bin/ls", true},
{[]string{"/bin/ls", "/bin/false"}, "/bin/false", true},
{[]string{"/bin/ls", "/bin/false"}, "/bin/bar", false},
{[]string{"/bin/*ls*"}, "/bin/ls", true},
{[]string{"/bin/*ls*"}, "/bin/false", true},
{[]string{"bin/ls"}, "/bin/ls", false},
{[]string{"./bin/ls"}, "/bin/ls", false},
{[]string{"*/bin/ls"}, "/bin/ls", false},
}

for _, d := range data {
matched := checkPathIsInGlobs(d.globs, d.toMatch)
assert.Equal(d.expected, matched, "%+v", d)
}
}

0 comments on commit 151e6fc

Please sign in to comment.