summaryrefslogtreecommitdiff
path: root/test/e2e
diff options
context:
space:
mode:
authorToshiki Sonoda <sonoda.toshiki@fujitsu.com>2022-09-02 16:20:26 +0900
committerToshiki Sonoda <sonoda.toshiki@fujitsu.com>2022-09-06 20:17:11 +0900
commita9a411f8a83ab5644582b8929a32abacc18a17fc (patch)
treee94196c3d5f7936f55d36041c67276dcb0a980ae /test/e2e
parent9ab6449e36792734853eb59161ccd3bfe5d0d509 (diff)
downloadpodman-a9a411f8a83ab5644582b8929a32abacc18a17fc.tar.gz
podman-a9a411f8a83ab5644582b8929a32abacc18a17fc.tar.bz2
podman-a9a411f8a83ab5644582b8929a32abacc18a17fc.zip
Add generate systemd -e/--env option
-e/--env option sets environment variables to the systemd unit files. Fixes: #15523 Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
Diffstat (limited to 'test/e2e')
-rw-r--r--test/e2e/generate_systemd_test.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/e2e/generate_systemd_test.go b/test/e2e/generate_systemd_test.go
index 45a2f1f86..f47abbc13 100644
--- a/test/e2e/generate_systemd_test.go
+++ b/test/e2e/generate_systemd_test.go
@@ -600,4 +600,75 @@ var _ = Describe("Podman generate systemd", func() {
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(ContainSubstring(" --label key={{someval}}"))
})
+
+ It("podman generate systemd --env", func() {
+ session := podmanTest.RunTopContainer("test")
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "foo=bar", "-e", "hoge=fuga", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("Environment=foo=bar"))
+ Expect(session.OutputToString()).To(ContainSubstring("Environment=hoge=fuga"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "=bar", "-e", "hoge=fuga", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(125))
+ Expect(session.ErrorToString()).To(ContainSubstring("invalid environment variable"))
+
+ // Use -e/--env option with --new option
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "foo=bar", "-e", "hoge=fuga", "--new", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("Environment=foo=bar"))
+ Expect(session.OutputToString()).To(ContainSubstring("Environment=hoge=fuga"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "foo=bar", "-e", "=fuga", "--new", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(125))
+ Expect(session.ErrorToString()).To(ContainSubstring("invalid environment variable"))
+
+ // Escape systemd arguments
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "BAR=my test", "-e", "USER=%a", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("\"BAR=my test\""))
+ Expect(session.OutputToString()).To(ContainSubstring("USER=%%a"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "BAR=my test", "-e", "USER=%a", "--new", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("\"BAR=my test\""))
+ Expect(session.OutputToString()).To(ContainSubstring("USER=%%a"))
+
+ // Specify the environment variables without a value
+ os.Setenv("FOO1", "BAR1")
+ os.Setenv("FOO2", "BAR2")
+ os.Setenv("FOO3", "BAR3")
+ defer os.Unsetenv("FOO1")
+ defer os.Unsetenv("FOO2")
+ defer os.Unsetenv("FOO3")
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "FOO1", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR1"))
+ Expect(session.OutputToString()).NotTo(ContainSubstring("BAR2"))
+ Expect(session.OutputToString()).NotTo(ContainSubstring("BAR3"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "FOO*", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR1"))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR2"))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR3"))
+
+ session = podmanTest.Podman([]string{"generate", "systemd", "--env", "FOO*", "--new", "test"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR1"))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR2"))
+ Expect(session.OutputToString()).To(ContainSubstring("BAR3"))
+ })
})