-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlshort_test.go
52 lines (45 loc) · 1.08 KB
/
lshort_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
package lshort
import (
"testing"
"github.com/dgraph-io/badger"
)
func TestShrinkAndExpandBolt(t *testing.T) {
tts := []string{"test", "test1", "test2", "test3", "test4", "test5", "test6", "test7"}
ls, err := NewLinkShortnerBolt("db.tmp", nil)
if err != nil {
t.Errorf("unable to create a shrinker: %v", err)
}
for _, tt := range tts {
key, err := ls.Shrink(tt)
if err != nil {
t.Errorf("unable to shrink url: %v", err)
}
url, err := ls.Expand(key)
if err != nil {
t.Errorf("unable to expand url: %v", err)
}
if url != tt {
t.Fail()
}
}
}
func TestShrinkAndExpandBadger(t *testing.T) {
tts := []string{"test", "test1", "test2", "test3", "test4", "test5", "test6", "test7"}
ls, err := NewLinkShortnerBadger("db_1.tmp", badger.DefaultOptions)
if err != nil {
t.Errorf("unable to create a shrinker: %v", err)
}
for _, tt := range tts {
key, err := ls.Shrink(tt)
if err != nil {
t.Errorf("unable to shrink url: %v", err)
}
url, err := ls.Expand(key)
if err != nil {
t.Errorf("unable to expand url: %v", err)
}
if url != tt {
t.Fail()
}
}
}