-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_test.go
37 lines (28 loc) · 880 Bytes
/
url_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
package rrpubsub
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseUrl(t *testing.T) {
assert := assert.New(t)
addr, opts, err := parseUrl("redis://")
assert.NoError(err)
assert.Equal(len(opts), 1)
assert.Equal(addr, "localhost:6379")
addr, opts, err = parseUrl("")
assert.Error(err)
addr, opts, err = parseUrl("http://localhost")
assert.Error(err)
assert.Equal(err.Error(), "invalid redis URL scheme: http")
addr, opts, err = parseUrl("redis://test:pass@localhost")
assert.NoError(err)
assert.Equal(len(opts), 2)
assert.Equal(addr, "localhost:6379")
addr, opts, err = parseUrl("redis://test:pass@localhost/1")
assert.NoError(err)
assert.Equal(len(opts), 3)
assert.Equal(addr, "localhost:6379")
addr, opts, err = parseUrl("redis://localhost/invalid")
assert.Error(err)
assert.Equal(err.Error(), "invalid database: invalid")
}