-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshrt_test.go
56 lines (50 loc) · 1.24 KB
/
shrt_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
package goshrt_test
import (
"testing"
"github.com/storvik/goshrt"
)
func TestShrt_Validation(t *testing.T) {
t.Run("Validate_Destination", func(t *testing.T) {
var tests = []struct {
s goshrt.Shrt
valid bool
}{
{goshrt.Shrt{Dest: "http://golang.org"}, true},
{goshrt.Shrt{Dest: "http://golang.org:3000"}, true},
{goshrt.Shrt{Dest: "https://golang.org"}, true},
{goshrt.Shrt{Dest: "golang.org"}, false},
{goshrt.Shrt{Dest: "https://golang.org/go"}, true},
{goshrt.Shrt{Dest: "http://golang.org/go.html"}, true},
}
for _, tt := range tests {
if v := tt.s.ValidDest(); v != tt.valid {
t.Errorf("%s: expected valid: %t, got %t", tt.s.Dest, tt.valid, v)
}
}
})
}
func TestShrt_ValidateSlug(t *testing.T) {
t.Run("OK", func(t *testing.T) {
var tests = []struct {
slug string
valid bool
}{
{"rRwfyu9", true},
{"api/rstrst", false},
{"public", false},
{"api", false},
{"public/hello", false},
{"apitrten", true},
{"pubclico", true},
{"239874str", true},
{"rst?strrts", false},
{"rst#strrts", false},
}
for _, tt := range tests {
b := goshrt.ValidateSlug(tt.slug)
if b != tt.valid {
t.Errorf("%s: expected valid: %t, got %t", tt.slug, tt.valid, b)
}
}
})
}