e2e: Add assert-key-is-regex check to quadlet e2e testsuite
We will use this later
@@ -117,6 +117,26 @@ func (t *quadletTestcase) assertKeyIs(args []string, unit *parser.UnitFile) bool
return true
}
+func (t *quadletTestcase) assertKeyIsRegex(args []string, unit *parser.UnitFile) bool {
+ Expect(len(args)).To(BeNumerically(">=", 3))
+ group := args[0]
+ key := args[1]
+ values := args[2:]
+
+ realValues := unit.LookupAll(group, key)
+ if len(realValues) != len(values) {
+ return false
+ }
+
+ for i := range realValues {
+ matched, _ := regexp.MatchString(values[i], realValues[i])
+ if !matched {
+ return false
+ }
+ }
+ return true
+}
+
func (t *quadletTestcase) assertKeyContains(args []string, unit *parser.UnitFile) bool {
Expect(args).To(HaveLen(3))
group := args[0]
@@ -209,6 +229,8 @@ func (t *quadletTestcase) doAssert(check []string, unit *parser.UnitFile, sessio
ok = t.assertStdErrContains(args, session)
case "assert-key-is":
ok = t.assertKeyIs(args, unit)
+ case "assert-key-is-regex":
+ ok = t.assertKeyIsRegex(args, unit)
case "assert-key-contains":
ok = t.assertKeyContains(args, unit)
case "assert-podman-args":
