-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_short_test.go
44 lines (38 loc) · 1.12 KB
/
url_short_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
package main
import (
"testing"
"time"
)
var urlTab = []URLData{URLData{"www.abc.com/longlongurlkjjsss", "ti.ny/10c2398f", time.Time{}}, URLData{"www.xyz.com/longlongurl2nmmmsssakkssstyy", "ti.ny/f17fc388", time.Time{}}, URLData{"www.efg.com/longlongurl3nhgjkkkssslkkhhaa", "ti.ny/0de0929b", time.Time{}}}
func TestGetShortURL(t *testing.T) {
updateUrlThreshold = len(urlTab)
for _, lu := range urlTab {
surl := GetShortURL(lu.LongURL)
if surl != lu.ShortURL {
t.Errorf("Failed to get short url")
} else {
surl2 := GetShortURL(lu.LongURL)
if surl != surl2 {
t.Errorf("Failed to match short url with previous one")
} else {
t.Logf("Success:Got short url = %s", surl)
}
}
}
StoreURLTable()
}
func TestInMemURLs(t *testing.T) {
for _, lu := range urlTab {
if URLTable[lu.LongURL].ShortURL != lu.ShortURL {
t.Errorf("Failed to match short url with in-memory URL Table")
}
}
}
func TestInFileURLs(t *testing.T) {
inFileURLs := LoadURLTable()
for _, lu := range urlTab {
if inFileURLs[lu.LongURL].ShortURL != lu.ShortURL {
t.Errorf("Failed to match short url with in-file URL Table")
}
}
}