aboutsummaryrefslogtreecommitdiff
path: root/pkg/systemd/generate/common_test.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-08-18 11:28:46 +0200
committerMatthew Heon <matthew.heon@pm.me>2020-08-20 12:21:49 -0400
commitb5b782f2584e59534ae1d66551de0e04fc3c0038 (patch)
tree7b73bd343e8341c5ca4bfcaff7109e0b104e79df /pkg/systemd/generate/common_test.go
parent402d002184fa33b8aa7bfe91a83b04ba80425e28 (diff)
downloadpodman-b5b782f2584e59534ae1d66551de0e04fc3c0038.tar.gz
podman-b5b782f2584e59534ae1d66551de0e04fc3c0038.tar.bz2
podman-b5b782f2584e59534ae1d66551de0e04fc3c0038.zip
generate systemd: quote arguments with whitespace
Make sure that arguments with whitespace are properly quoted so they are interpreted as one (and not multiple ones) by systemd. Now `-e tz="america/new york"` will be generated as `-e "tz=america/new york"`. The quotes are moving but the argument is still correct. Fixes: #7285 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/systemd/generate/common_test.go')
-rw-r--r--pkg/systemd/generate/common_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/systemd/generate/common_test.go b/pkg/systemd/generate/common_test.go
index 389c30f59..d0ec5637c 100644
--- a/pkg/systemd/generate/common_test.go
+++ b/pkg/systemd/generate/common_test.go
@@ -28,3 +28,28 @@ func TestFilterPodFlags(t *testing.T) {
}
}
}
+
+func TestQuoteArguments(t *testing.T) {
+ tests := []struct {
+ input []string
+ output []string
+ }{
+ {
+ []string{"foo", "bar=\"arg\""},
+ []string{"foo", "bar=\"arg\""},
+ },
+ {
+ []string{"foo", "bar=\"arg with space\""},
+ []string{"foo", "\"bar=\\\"arg with space\\\"\""},
+ },
+ {
+ []string{"foo", "bar=\"arg with\ttab\""},
+ []string{"foo", "\"bar=\\\"arg with\\ttab\\\"\""},
+ },
+ }
+
+ for _, test := range tests {
+ quoted := quoteArguments(test.input)
+ assert.Equal(t, test.output, quoted)
+ }
+}