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 authored and fidencio committed Nov 11, 2020
1 parent 9b733a9 commit d4b8f61
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions virtcontainers/pkg/oci/utils_test.go
Original file line number Diff line number Diff line change
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 d4b8f61

Please sign in to comment.