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 regexpContains function
Browse files Browse the repository at this point in the history
James O.D Hunt: "But also, regexpContains() and
checkPathIsInGlobList() seem like good candidates for some unit
tests. The "look" obvious, but a few boundary condition tests would be
useful I think (filenames with spaces, backslashes, special
characters, and relative & absolute paths are also an interesting
thought here)."

There aren't that many boundary conditions on a list with regexps,
if you assume the regexp match function itself works. However, the
tests is useful in documenting expectations.

Fixes: #3004

Suggested-by: James O.D. Hunt <[email protected]>
Signed-off-by: Christophe de Dinechin <[email protected]>
  • Loading branch information
c3d authored and fidencio committed Nov 11, 2020
1 parent ff869d5 commit 9b733a9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions virtcontainers/pkg/oci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,3 +954,31 @@ func TestIsCRIOContainerManager(t *testing.T) {
assert.Equal(tc.result, result, "test case %d", (i + 1))
}
}

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

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

data := []testData{
{[]string{}, "", false},
{[]string{}, "nonempty", false},
{[]string{"simple"}, "simple", true},
{[]string{"simple"}, "some_simple_text", true},
{[]string{"simple"}, "simp", false},
{[]string{"one", "two"}, "one", true},
{[]string{"one", "two"}, "two", true},
{[]string{"o*"}, "oooo", true},
{[]string{"o*"}, "oooa", true},
{[]string{"^o*$"}, "oooa", false},
}

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

0 comments on commit 9b733a9

Please sign in to comment.