mirror of
				https://github.com/containers/podman.git
				synced 2025-10-31 10:00:01 +08:00 
			
		
		
		
	Quadlet Kube: Add support for relative path for YAML file
If the provided path is relative, turn path to absolute Add regex verification option in tests Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
This commit is contained in:
		| @ -4,6 +4,7 @@ import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"regexp" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/containers/podman/v4/pkg/systemd/parser" | ||||
| @ -64,6 +65,20 @@ func matchSublistAt(full []string, pos int, sublist []string) bool { | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| func matchSublistRegexAt(full []string, pos int, sublist []string) bool { | ||||
| 	if len(sublist) > len(full)-pos { | ||||
| 		return false | ||||
| 	} | ||||
|  | ||||
| 	for i := range sublist { | ||||
| 		matched, err := regexp.MatchString(sublist[i], full[pos+i]) | ||||
| 		if err != nil || !matched { | ||||
| 			return false | ||||
| 		} | ||||
| 	} | ||||
| 	return true | ||||
| } | ||||
|  | ||||
| func findSublist(full []string, sublist []string) int { | ||||
| 	if len(sublist) > len(full) { | ||||
| 		return -1 | ||||
| @ -123,6 +138,14 @@ func (t *quadletTestcase) assertPodmanFinalArgs(args []string, unit *parser.Unit | ||||
| 	return matchSublistAt(podmanArgs, len(podmanArgs)-len(args), args) | ||||
| } | ||||
|  | ||||
| func (t *quadletTestcase) assertPodmanFinalArgsRegex(args []string, unit *parser.UnitFile, key string) bool { | ||||
| 	podmanArgs, _ := unit.LookupLastArgs("Service", key) | ||||
| 	if len(podmanArgs) < len(args) { | ||||
| 		return false | ||||
| 	} | ||||
| 	return matchSublistRegexAt(podmanArgs, len(podmanArgs)-len(args), args) | ||||
| } | ||||
|  | ||||
| func (t *quadletTestcase) assertStartPodmanArgs(args []string, unit *parser.UnitFile) bool { | ||||
| 	return t.assertPodmanArgs(args, unit, "ExecStart") | ||||
| } | ||||
| @ -131,6 +154,10 @@ func (t *quadletTestcase) assertStartPodmanFinalArgs(args []string, unit *parser | ||||
| 	return t.assertPodmanFinalArgs(args, unit, "ExecStart") | ||||
| } | ||||
|  | ||||
| func (t *quadletTestcase) assertStartPodmanFinalArgsRegex(args []string, unit *parser.UnitFile) bool { | ||||
| 	return t.assertPodmanFinalArgsRegex(args, unit, "ExecStart") | ||||
| } | ||||
|  | ||||
| func (t *quadletTestcase) assertStopPodmanArgs(args []string, unit *parser.UnitFile) bool { | ||||
| 	return t.assertPodmanArgs(args, unit, "ExecStop") | ||||
| } | ||||
| @ -139,6 +166,10 @@ func (t *quadletTestcase) assertStopPodmanFinalArgs(args []string, unit *parser. | ||||
| 	return t.assertPodmanFinalArgs(args, unit, "ExecStop") | ||||
| } | ||||
|  | ||||
| func (t *quadletTestcase) assertStopPodmanFinalArgsRegex(args []string, unit *parser.UnitFile) bool { | ||||
| 	return t.assertPodmanFinalArgsRegex(args, unit, "ExecStop") | ||||
| } | ||||
|  | ||||
| func (t *quadletTestcase) assertSymlink(args []string, unit *parser.UnitFile) bool { | ||||
| 	symlink := args[0] | ||||
| 	expectedTarget := args[1] | ||||
| @ -180,12 +211,16 @@ func (t *quadletTestcase) doAssert(check []string, unit *parser.UnitFile, sessio | ||||
| 		ok = t.assertStartPodmanArgs(args, unit) | ||||
| 	case "assert-podman-final-args": | ||||
| 		ok = t.assertStartPodmanFinalArgs(args, unit) | ||||
| 	case "assert-podman-final-args-regex": | ||||
| 		ok = t.assertStartPodmanFinalArgsRegex(args, unit) | ||||
| 	case "assert-symlink": | ||||
| 		ok = t.assertSymlink(args, unit) | ||||
| 	case "assert-podman-stop-args": | ||||
| 		ok = t.assertStopPodmanArgs(args, unit) | ||||
| 	case "assert-podman-stop-final-args": | ||||
| 		ok = t.assertStopPodmanFinalArgs(args, unit) | ||||
| 	case "assert-podman-stop-final-args-regex": | ||||
| 		ok = t.assertStopPodmanFinalArgsRegex(args, unit) | ||||
| 	default: | ||||
| 		return fmt.Errorf("Unsupported assertion %s", op) | ||||
| 	} | ||||
| @ -323,6 +358,7 @@ var _ = Describe("quadlet system generator", func() { | ||||
|  | ||||
| 		Entry("Basic kube", "basic.kube"), | ||||
| 		Entry("Syslog Identifier", "syslog.identifier.kube"), | ||||
| 		Entry("Absolute Path", "absolute.path.kube"), | ||||
| 	) | ||||
|  | ||||
| }) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Ygal Blum
					Ygal Blum