mirror of
https://github.com/containers/podman.git
synced 2025-11-29 09:37:38 +08:00
Introduce assert-has-key assertion
Signed-off-by: Dmitry Konishchev <konishchev@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/podman/v6/pkg/systemd/parser"
|
"github.com/containers/podman/v6/pkg/systemd/parser"
|
||||||
@@ -172,6 +173,16 @@ func (t *quadletTestcase) assertKeyIs(args []string, unit *parser.UnitFile) bool
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *quadletTestcase) assertHasKey(args []string, unit *parser.UnitFile) bool {
|
||||||
|
Expect(args).To(HaveLen(3))
|
||||||
|
group := args[0]
|
||||||
|
key := args[1]
|
||||||
|
value := args[2]
|
||||||
|
|
||||||
|
realValues := unit.LookupAll(group, key)
|
||||||
|
return slices.Contains(realValues, value)
|
||||||
|
}
|
||||||
|
|
||||||
func (t *quadletTestcase) assertKeyIsEmpty(args []string, unit *parser.UnitFile) bool {
|
func (t *quadletTestcase) assertKeyIsEmpty(args []string, unit *parser.UnitFile) bool {
|
||||||
Expect(args).To(HaveLen(2))
|
Expect(args).To(HaveLen(2))
|
||||||
group := args[0]
|
group := args[0]
|
||||||
@@ -540,6 +551,8 @@ func (t *quadletTestcase) doAssert(check []string, unit *parser.UnitFile, sessio
|
|||||||
ok = t.assertStdErrContains(args, session)
|
ok = t.assertStdErrContains(args, session)
|
||||||
case "assert-key-is":
|
case "assert-key-is":
|
||||||
ok = t.assertKeyIs(args, unit)
|
ok = t.assertKeyIs(args, unit)
|
||||||
|
case "assert-has-key":
|
||||||
|
ok = t.assertHasKey(args, unit)
|
||||||
case "assert-key-is-empty":
|
case "assert-key-is-empty":
|
||||||
ok = t.assertKeyIsEmpty(args, unit)
|
ok = t.assertKeyIsEmpty(args, unit)
|
||||||
case "assert-key-is-regex":
|
case "assert-key-is-regex":
|
||||||
|
|||||||
Reference in New Issue
Block a user