mirror of
https://github.com/containers/podman.git
synced 2025-12-01 10:38:05 +08:00
Merge pull request #25626 from jankaluza/24875
Add --env and --unsetenv to podman update.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/containers/storage/pkg/fileutils"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
. "github.com/onsi/gomega/gexec"
|
||||
)
|
||||
|
||||
var _ = Describe("Podman update", func() {
|
||||
@@ -243,4 +244,65 @@ var _ = Describe("Podman update", func() {
|
||||
podmanTest.CheckContainerSingleField(testCtr, restartPolicyName, "always")
|
||||
podmanTest.CheckContainerSingleField(testCtr, restartPolicyRetries, "0")
|
||||
})
|
||||
|
||||
It("podman update sets/unsets environment variables", func() {
|
||||
testCtr := "test-ctr-name"
|
||||
|
||||
// Test that the variable is not set.
|
||||
ctr1 := podmanTest.Podman([]string{"run", "-t", "--name", testCtr, ALPINE, "printenv", "FOO"})
|
||||
ctr1.WaitWithDefaultTimeout()
|
||||
Expect(ctr1).Should(Exit(1))
|
||||
|
||||
// Test that variable can be set and existing variables are not overridden.
|
||||
update := podmanTest.Podman([]string{"update", "--env", "FOO=BAR", testCtr})
|
||||
update.WaitWithDefaultTimeout()
|
||||
Expect(update).Should(ExitCleanly())
|
||||
|
||||
session := podmanTest.Podman([]string{"start", "--attach", testCtr})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
env := session.OutputToString()
|
||||
Expect(env).To(ContainSubstring("BAR"))
|
||||
|
||||
session = podmanTest.Podman([]string{"inspect", testCtr, "--format", "{{.Config.Env}}"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
env = session.OutputToString()
|
||||
Expect(env).To(ContainSubstring("FOO=BAR"))
|
||||
Expect(env).To(ContainSubstring("PATH="))
|
||||
|
||||
// Test that variable can be updated.
|
||||
update = podmanTest.Podman([]string{"update", "--env", "FOO=RAB", testCtr})
|
||||
update.WaitWithDefaultTimeout()
|
||||
Expect(update).Should(ExitCleanly())
|
||||
|
||||
session = podmanTest.Podman([]string{"start", "--attach", testCtr})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
env = session.OutputToString()
|
||||
Expect(env).To(ContainSubstring("RAB"))
|
||||
|
||||
session = podmanTest.Podman([]string{"inspect", testCtr, "--format", "{{.Config.Env}}"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
env = session.OutputToString()
|
||||
Expect(env).To(ContainSubstring("FOO=RAB"))
|
||||
Expect(env).To(ContainSubstring("PATH="))
|
||||
|
||||
// Test that variable can be unset.
|
||||
update = podmanTest.Podman([]string{"update", "--unsetenv", "FOO", testCtr})
|
||||
update.WaitWithDefaultTimeout()
|
||||
Expect(update).Should(ExitCleanly())
|
||||
|
||||
session = podmanTest.Podman([]string{"start", "--attach", testCtr})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(1))
|
||||
|
||||
session = podmanTest.Podman([]string{"inspect", testCtr, "--format", "{{.Config.Env}}"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
env = session.OutputToString()
|
||||
Expect(env).ToNot(ContainSubstring("FOO"))
|
||||
Expect(env).To(ContainSubstring("PATH="))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user