-
Notifications
You must be signed in to change notification settings - Fork 0
/
pass-generator_test.go
48 lines (42 loc) · 1.27 KB
/
pass-generator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"strings"
"testing"
)
func TestGeneratePassword(t *testing.T) {
// Test with lowercase letters
*useLower = true
password := generatePassword()
if !strings.ContainsAny(password, lowercase) {
t.Errorf("Expected password to contain at least one lowercase letter")
}
// Test with uppercase letters
*useLower = false
*useUpper = true
password = generatePassword()
if !strings.ContainsAny(password, uppercase) {
t.Errorf("Expected password to contain at least one uppercase letter")
}
// Test with digits
*useUpper = false
*useDigits = true
password = generatePassword()
if !strings.ContainsAny(password, digits) {
t.Errorf("Expected password to contain at least one digit")
}
// Test with special characters
*useDigits = false
*useSpecial = true
password = generatePassword()
if !strings.ContainsAny(password, special) {
t.Errorf("Expected password to contain at least one special character")
}
// Test with no character set selected
*useSpecial = false
defer func() {
if r := recover(); r == nil {
t.Errorf("Expected function to panic when no character set is selected")
}
}()
generatePassword()
}