mirror of
https://github.com/containers/podman.git
synced 2025-06-19 08:09:12 +08:00
--no-header flag implementation for generate systemd
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
This commit is contained in:
@ -37,9 +37,11 @@ func TestValidateRestartPolicyPod(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreatePodSystemdUnit(t *testing.T) {
|
||||
podGood := `# pod-123abc.service
|
||||
# autogenerated by Podman CI
|
||||
|
||||
serviceInfo := `# pod-123abc.service
|
||||
`
|
||||
headerInfo := `# autogenerated by Podman CI
|
||||
`
|
||||
podContent := `
|
||||
[Unit]
|
||||
Description=Podman pod-123abc.service
|
||||
Documentation=man:podman-generate-systemd(1)
|
||||
@ -61,6 +63,8 @@ Type=forking
|
||||
[Install]
|
||||
WantedBy=multi-user.target default.target
|
||||
`
|
||||
podGood := serviceInfo + headerInfo + podContent
|
||||
podGoodNoHeaderInfo := serviceInfo + podContent
|
||||
|
||||
podGoodNamedNew := `# pod-123abc.service
|
||||
# autogenerated by Podman CI
|
||||
@ -171,11 +175,12 @@ WantedBy=multi-user.target default.target
|
||||
`
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
info podInfo
|
||||
want string
|
||||
new bool
|
||||
wantErr bool
|
||||
name string
|
||||
info podInfo
|
||||
want string
|
||||
new bool
|
||||
noHeader bool
|
||||
wantErr bool
|
||||
}{
|
||||
{"pod",
|
||||
podInfo{
|
||||
@ -192,6 +197,24 @@ WantedBy=multi-user.target default.target
|
||||
podGood,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{"pod noHeader",
|
||||
podInfo{
|
||||
Executable: "/usr/bin/podman",
|
||||
ServiceName: "pod-123abc",
|
||||
InfraNameOrID: "jadda-jadda-infra",
|
||||
RestartPolicy: "always",
|
||||
PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid",
|
||||
StopTimeout: 42,
|
||||
PodmanVersion: "CI",
|
||||
RequiredServices: []string{"container-1", "container-2"},
|
||||
CreateCommand: []string{"podman", "pod", "create", "--name", "foo", "bar=arg with space"},
|
||||
},
|
||||
podGoodNoHeaderInfo,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{"pod with root args",
|
||||
podInfo{
|
||||
@ -208,6 +231,7 @@ WantedBy=multi-user.target default.target
|
||||
podGood,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{"pod --new",
|
||||
podInfo{
|
||||
@ -224,6 +248,7 @@ WantedBy=multi-user.target default.target
|
||||
podGoodNamedNew,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{"pod --new with root args",
|
||||
podInfo{
|
||||
@ -240,6 +265,7 @@ WantedBy=multi-user.target default.target
|
||||
podGoodNamedNewWithRootArgs,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{"pod --new with --replace=false",
|
||||
podInfo{
|
||||
@ -256,6 +282,7 @@ WantedBy=multi-user.target default.target
|
||||
podGoodNamedNewWithReplaceFalse,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{"pod --new with double curly braces",
|
||||
podInfo{
|
||||
@ -272,6 +299,7 @@ WantedBy=multi-user.target default.target
|
||||
podNewLabelWithCurlyBraces,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
@ -279,7 +307,8 @@ WantedBy=multi-user.target default.target
|
||||
test := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
opts := entities.GenerateSystemdOptions{
|
||||
New: test.new,
|
||||
New: test.new,
|
||||
NoHeader: test.noHeader,
|
||||
}
|
||||
got, err := executePodTemplate(&test.info, opts)
|
||||
if (err != nil) != test.wantErr {
|
||||
|
Reference in New Issue
Block a user