aboutsummaryrefslogtreecommitdiff
path: root/libpod/runtime_test.go
diff options
context:
space:
mode:
authorDoug Rabson <dfr@rabson.org>2022-08-31 18:02:38 +0100
committerDoug Rabson <dfr@rabson.org>2022-09-01 10:27:04 +0100
commitb667d7340c1717720216ebdb1c62052006e7ac5f (patch)
tree38e43cf9687bad09cc846960967c29b8f6679ee0 /libpod/runtime_test.go
parent72f4c77139adf61bc39890e08ed9b86c365ae09b (diff)
downloadpodman-b667d7340c1717720216ebdb1c62052006e7ac5f.tar.gz
podman-b667d7340c1717720216ebdb1c62052006e7ac5f.tar.bz2
podman-b667d7340c1717720216ebdb1c62052006e7ac5f.zip
libpod: Ensure that generated container names are random
Fixes #15569. Signed-off-by: Doug Rabson <dfr@rabson.org>
Diffstat (limited to 'libpod/runtime_test.go')
-rw-r--r--libpod/runtime_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/libpod/runtime_test.go b/libpod/runtime_test.go
new file mode 100644
index 000000000..2e16c7fcd
--- /dev/null
+++ b/libpod/runtime_test.go
@@ -0,0 +1,28 @@
+package libpod
+
+import (
+ "math/rand"
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func Test_generateName(t *testing.T) {
+ state, path, _, err := getEmptyBoltState()
+ assert.NoError(t, err)
+ defer os.RemoveAll(path)
+ defer state.Close()
+
+ r := &Runtime{
+ state: state,
+ }
+
+ // Test that (*Runtime).generateName returns different names
+ // if called twice, even if the global RNG has the default
+ // seed.
+ n1, _ := r.generateName()
+ rand.Seed(1)
+ n2, _ := r.generateName()
+ assert.NotEqual(t, n1, n2)
+}