-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpassman_test.go
60 lines (51 loc) · 1.96 KB
/
passman_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
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"github.com/seanpont/assert"
"strings"
"testing"
)
func TestServices(t *testing.T) {
assert := assert.Assert(t)
services := new(Services)
assert.Equal(len(services.Services), 0)
// Addition
services.Add(Service{Name: "google.com", Password: "asdf1234", Meta: "Personal"})
assert.Equal(len(services.Services), 1)
assert.Equal(services.Services[0].Name, "google.com")
// replacement
services.Add(Service{Name: "google.com", Password: "lkjpoiu"})
assert.Equal(len(services.Services), 1)
assert.Equal(services.Services[0].Password, "lkjpoiu")
// Addition
services.Add(Service{Name: "facebook.com", Password: "1234"})
assert.Equal(len(services.Services), 2)
// another replacement
services.Add(Service{Name: "google.com", Password: "asghasd"})
assert.Equal(services.Get("google.com").Password, "asghasd")
assert.Equal(len(services.Services), 2)
services.Add(Service{Name: "golang.org"})
goServices := services.Search("go")
assert.Equal(len(goServices), 2)
assert.True(goServices[0].Name[:2] == "go", "Service 0 begins with go")
assert.True(goServices[1].Name[:2] == "go", "Service 1 begins with go")
assert.Equal(len(services.Search("*")), 3)
}
func TestPasswordGeneration(t *testing.T) {
assert := assert.Assert(t)
generator := NewPasswordGenerator("lunc20")
assert.Equal(generator.length, 20)
password := generator.generate()
assert.Equal(len(password), 20)
assert.True(strings.ContainsAny(password, LOWERCASE), "missing characters")
assert.True(strings.ContainsAny(password, UPPERCASE), "missing characters")
assert.True(strings.ContainsAny(password, NUMBERS), "missing characters")
assert.True(strings.ContainsAny(password, CHARACTERS), "missing characters")
}
func TestPasswordGenerationWithWords(t *testing.T) {
assert := assert.Assert(t)
generator := NewPasswordGenerator("w24")
assert.Equal(generator.length, 24)
assert.Equal(generator.words, true)
password := generator.generate()
assert.True(len(password) >= 24, "length")
}