MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestGenerateASCIIPassword

Function TestGenerateASCIIPassword

internal/util/secrets_test.go:71–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestGenerateASCIIPassword(t *testing.T) {
72 for _, length := range []int{0, 1, 2, 3, 5, 20, 200} {
73 password, err := GenerateASCIIPassword(length)
74
75 assert.NilError(t, err)
76 assert.Equal(t, length, len(password))
77
78 // Check every rune in the string. See [TestPolicyASCII].
79 for _, c := range password {
80 assert.Assert(t, strings.ContainsRune(policyASCII, c), "%q is not acceptable", c)
81 }
82 }
83
84 previous := sets.Set[string]{}
85 for range 10 {
86 password, err := GenerateASCIIPassword(5)
87
88 assert.NilError(t, err)
89 assert.Equal(t, 5, len(password))
90
91 // Check every rune in the string. See [TestPolicyASCII].
92 for _, c := range password {
93 assert.Assert(t, strings.ContainsRune(policyASCII, c), "%q is not acceptable", c)
94 }
95
96 assert.Assert(t, !previous.Has(password), "%q generated twice", password)
97 previous.Insert(password)
98 }
99}
100
101func TestPolicyASCII(t *testing.T) {
102 // [GenerateASCIIPassword] used to pick random characters by doing

Callers

nothing calls this directly

Calls 4

GenerateASCIIPasswordFunction · 0.85
InsertMethod · 0.80
HasMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected