-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15581 from dfr/random-names
libpod: Ensure that generated container names are random
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |