aboutsummaryrefslogtreecommitdiff
path: root/pkg/systemd
diff options
context:
space:
mode:
authorBoaz Shuster <boaz.shuster.github@gmail.com>2021-11-01 19:53:20 +0200
committerBoaz Shuster <boaz.shuster.github@gmail.com>2021-11-01 19:53:20 +0200
commit15eb016017e39c7370d169790e15744746d54cd7 (patch)
treea84ee62d55bc2f4acb6a6b37b4ccef0a3c42ad60 /pkg/systemd
parent7494876000daa3f2a58d07f89561fd3ea447819a (diff)
downloadpodman-15eb016017e39c7370d169790e15744746d54cd7.tar.gz
podman-15eb016017e39c7370d169790e15744746d54cd7.tar.bz2
podman-15eb016017e39c7370d169790e15744746d54cd7.zip
add unit test to containers_test
Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
Diffstat (limited to 'pkg/systemd')
-rw-r--r--pkg/systemd/generate/containers_test.go73
1 files changed, 71 insertions, 2 deletions
diff --git a/pkg/systemd/generate/containers_test.go b/pkg/systemd/generate/containers_test.go
index f46513459..85aeb92b8 100644
--- a/pkg/systemd/generate/containers_test.go
+++ b/pkg/systemd/generate/containers_test.go
@@ -522,6 +522,32 @@ NotifyAccess=all
[Install]
WantedBy=multi-user.target default.target
`
+
+ templateGood := `# container-foo@.service
+# autogenerated by Podman CI
+
+[Unit]
+Description=Podman container-foo.service for %I
+Documentation=man:podman-generate-systemd(1)
+Wants=network-online.target
+After=network-online.target
+RequiresMountsFor=/var/run/containers/storage
+
+[Service]
+Environment=PODMAN_SYSTEMD_UNIT=%n-%i
+Restart=on-failure
+StartLimitBurst=42
+TimeoutStopSec=70
+ExecStartPre=/bin/rm -f %t/%n.ctr-id
+ExecStart=/usr/bin/podman run --name=container-foo-%i --cidfile=%t/%n.ctr-id --cgroups=no-conmon --rm --sdnotify=conmon -d awesome-image:latest
+ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
+ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id
+Type=notify
+NotifyAccess=all
+
+[Install]
+WantedBy=multi-user.target default.target
+`
tests := []struct {
name string
info containerInfo
@@ -529,6 +555,7 @@ WantedBy=multi-user.target default.target
new bool
noHeader bool
wantErr bool
+ template bool
}{
{"good with id",
@@ -547,6 +574,7 @@ WantedBy=multi-user.target default.target
false,
false,
false,
+ false,
},
{"good with noHeader",
containerInfo{
@@ -564,6 +592,7 @@ WantedBy=multi-user.target default.target
false,
true,
false,
+ false,
},
{"good with name",
containerInfo{
@@ -581,6 +610,7 @@ WantedBy=multi-user.target default.target
false,
false,
false,
+ false,
},
{"good with name and bound to",
containerInfo{
@@ -599,6 +629,7 @@ WantedBy=multi-user.target default.target
false,
false,
false,
+ false,
},
{"good with name and generic",
containerInfo{
@@ -617,6 +648,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with name and sdnotify",
containerInfo{
@@ -635,6 +667,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with explicit short detach param",
containerInfo{
@@ -653,6 +686,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with explicit short detach param and podInfo",
containerInfo{
@@ -674,6 +708,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with explicit full detach param",
containerInfo{
@@ -692,6 +727,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with id and no param",
containerInfo{
@@ -710,6 +746,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with explicit detach=true param",
containerInfo{
@@ -728,6 +765,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with explicit detach=false param",
containerInfo{
@@ -746,6 +784,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with explicit detach=false param",
containerInfo{
@@ -764,6 +803,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with multiple detach=false params",
containerInfo{
@@ -782,6 +822,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with multiple shorthand params detach first",
containerInfo{
@@ -800,6 +841,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with multiple shorthand params detach last",
containerInfo{
@@ -818,6 +860,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with container create",
containerInfo{
@@ -836,6 +879,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with journald log tag (see #9034)",
containerInfo{
@@ -854,6 +898,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with special chars",
containerInfo{
@@ -872,6 +917,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with ID files",
containerInfo{
@@ -890,6 +936,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with pod ID files",
containerInfo{
@@ -911,6 +958,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with environment variables",
containerInfo{
@@ -930,6 +978,7 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
},
{"good with restart policy",
containerInfo{
@@ -948,14 +997,34 @@ WantedBy=multi-user.target default.target
true,
false,
false,
+ false,
+ },
+ {"good template",
+ containerInfo{
+ Executable: "/usr/bin/podman",
+ ServiceName: "container-foo",
+ ContainerNameOrID: "foo",
+ PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid",
+ StopTimeout: 10,
+ PodmanVersion: "CI",
+ GraphRoot: "/var/lib/containers/storage",
+ RunRoot: "/var/run/containers/storage",
+ CreateCommand: []string{"I'll get stripped", "create", "--restart", "on-failure:42", "awesome-image:latest"},
+ },
+ templateGood,
+ true,
+ false,
+ false,
+ true,
},
}
for _, tt := range tests {
test := tt
t.Run(tt.name, func(t *testing.T) {
opts := entities.GenerateSystemdOptions{
- New: test.new,
- NoHeader: test.noHeader,
+ New: test.new,
+ NoHeader: test.noHeader,
+ TemplateUnitFile: test.template,
}
test.info.RestartPolicy = define.DefaultRestartPolicy
got, err := executeContainerTemplate(&test.info, opts)