forked from schollz/cowyo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
executable file
·54 lines (49 loc) · 1.15 KB
/
utils_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
package main
import (
"testing"
)
func BenchmarkAlliterativeAnimal(b *testing.B) {
for i := 0; i < b.N; i++ {
randomAlliterateCombo()
}
}
func TestReverseList(t *testing.T) {
s := []int64{1, 10, 2, 20}
if reverseSliceInt64(s)[0] != 20 {
t.Errorf("Could not reverse: %v", s)
}
s2 := []string{"a", "b", "d", "c"}
if reverseSliceString(s2)[0] != "c" {
t.Errorf("Could not reverse: %v", s2)
}
}
func TestHashing(t *testing.T) {
p := HashPassword("1234")
log.Debug(p)
err := CheckPasswordHash("1234", p)
if err != nil {
t.Errorf("Should be correct password")
}
err = CheckPasswordHash("1234lkjklj", p)
if err == nil {
t.Errorf("Should NOT be correct password")
}
}
func TestEncryption(t *testing.T) {
s, err := EncryptString("some string", "some password")
if err != nil {
t.Errorf("What")
}
log.Debug(s)
d, err := DecryptString(s, "some wrong password")
if err == nil {
t.Errorf("Should throw error for bad password")
}
d, err = DecryptString(s, "some password")
if err != nil {
t.Errorf("Should not throw password")
}
if d != "some string" {
t.Errorf("Problem decoding")
}
}