From e8f34e4579aaa7999fdf7df72a393c19f341f9f8 Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Thu, 27 Apr 2023 14:39:51 -0400 Subject: [PATCH] Add name-generation test Podman's container-name generation depends on the global RNG state being properly initialized (seeded). Should this not happen for some reason (or it's seeded with a static value), podman will generate the exact same repeating sequence of container names (assuming no clashes with existing containers). Add a test to confirm this is always the case. Signed-off-by: Chris Evich --- test/e2e/run_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index 465cbaee7e..6a8c098ea6 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -48,6 +48,36 @@ var _ = Describe("Podman run", func() { Expect(session).Should(Exit(0)) }) + // This test may seem entirely pointless, it is not. Due to compatibility + // and historical reasons, the container name generator uses a globally + // scoped RNG, seeded from a global state. An easy way to check if its + // been initialized properly (i.e. pseudo-non-deterministically) is + // checking if the name-generator spits out the same name twice. Because + // existing containers are checked when generating names, the test must ensure + // the first container is removed before creating a second. + It("podman generates different names for successive containers", func() { + var names [2]string + + for i := range names { + session := podmanTest.Podman([]string{"create", ALPINE, "true"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + cid := session.OutputToString() + Expect(cid).To(Not(Equal(""))) + + session = podmanTest.Podman([]string{"container", "inspect", "--format", "{{.Name}}", cid}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + names[i] = session.OutputToString() + Expect(names[i]).To(Not(Equal(""))) + + session = podmanTest.Podman([]string{"rm", cid}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + } + Expect(names[0]).ToNot(Equal(names[1]), "Podman generated duplicate successive container names, has the global RNG been seeded correctly?") + }) + It("podman run check /run/.containerenv", func() { session := podmanTest.Podman([]string{"run", ALPINE, "cat", "/run/.containerenv"}) session.WaitWithDefaultTimeout()