-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
49 lines (40 loc) · 1.08 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
package short
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestIsAlphaNumeric(t *testing.T) {
t.Run("empty", func(t *testing.T) {
require.True(t, isAlphaNumeric(""))
})
t.Run("alphanumeric", func(t *testing.T) {
require.True(t, isAlphaNumeric("aBsds323aaAAZZ"))
})
t.Run("non-alphanumeric", func(t *testing.T) {
require.False(t, isAlphaNumeric(" 1123aavvbb"))
})
}
func TestValidateUrl(t *testing.T) {
t.Run("no scheme", func(t *testing.T) {
err := validateUrl("www.google.com?aaa=bb")
require.NotNil(t, err)
require.Contains(t, err.Error(), "the url must have an 'https' or an 'http' scheme")
})
t.Run("invalid", func(t *testing.T) {
err := validateUrl("https://www com")
require.NotNil(t, err)
})
t.Run("valid", func(t *testing.T) {
err := validateUrl("https://www.com:4563/?aaa=fvvv#hash")
require.Nil(t, err)
})
}
func TestGeneratorRandomId(t *testing.T) {
for i := 0; i < 100; i++ {
id, err := generateRandomId()
require.Nil(t, err)
require.NotEmpty(t, id)
require.LessOrEqual(t, len(id), 7)
require.True(t, isAlphaNumeric(id))
}
}