MCPcopy
hub / github.com/redis/go-redis / TestParseURL

Function TestParseURL

options_test.go:15–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestParseURL(t *testing.T) {
16 cases := []struct {
17 url string
18 o *Options // expected value
19 err error
20 }{
21 {
22 url: "redis://localhost:123/1",
23 o: &Options{Addr: "localhost:123", DB: 1},
24 }, {
25 url: "redis://localhost:123",
26 o: &Options{Addr: "localhost:123"},
27 }, {
28 url: "redis://localhost/1",
29 o: &Options{Addr: "localhost:6379", DB: 1},
30 }, {
31 url: "redis://12345",
32 o: &Options{Addr: "12345:6379"},
33 }, {
34 url: "rediss://localhost:123",
35 o: &Options{Addr: "localhost:123", TLSConfig: &tls.Config{ /* no deep comparison */ }},
36 }, {
37 url: "rediss://localhost:123/?skip_verify=true",
38 o: &Options{Addr: "localhost:123", TLSConfig: &tls.Config{InsecureSkipVerify: true}},
39 }, {
40 url: "redis://:bar@localhost:123",
41 o: &Options{Addr: "localhost:123", Password: "bar"},
42 }, {
43 url: "redis://foo@localhost:123",
44 o: &Options{Addr: "localhost:123", Username: "foo"},
45 }, {
46 url: "redis://foo:bar@localhost:123",
47 o: &Options{Addr: "localhost:123", Username: "foo", Password: "bar"},
48 }, {
49 // multiple params
50 url: "redis://localhost:123/?db=2&read_timeout=2&pool_fifo=true",
51 o: &Options{Addr: "localhost:123", DB: 2, ReadTimeout: 2 * time.Second, PoolFIFO: true},
52 }, {
53 // special case handling for disabled timeouts
54 url: "redis://localhost:123/?db=2&conn_max_idle_time=0",
55 o: &Options{Addr: "localhost:123", DB: 2, ConnMaxIdleTime: -1},
56 }, {
57 // negative values disable timeouts as well
58 url: "redis://localhost:123/?db=2&conn_max_idle_time=-1",
59 o: &Options{Addr: "localhost:123", DB: 2, ConnMaxIdleTime: -1},
60 }, {
61 // absent timeout values will use defaults
62 url: "redis://localhost:123/?db=2&conn_max_idle_time=",
63 o: &Options{Addr: "localhost:123", DB: 2, ConnMaxIdleTime: 0},
64 }, {
65 url: "redis://localhost:123/?db=2&conn_max_idle_time", // missing "=" at the end
66 o: &Options{Addr: "localhost:123", DB: 2, ConnMaxIdleTime: 0},
67 }, {
68 url: "redis://localhost:123/?db=2&client_name=hi", // client name
69 o: &Options{Addr: "localhost:123", DB: 2, ClientName: "hi"},
70 }, {
71 url: "redis://localhost:123/?db=2&protocol=2", // RESP Protocol
72 o: &Options{Addr: "localhost:123", DB: 2, Protocol: 2},

Callers

nothing calls this directly

Calls 4

ParseURLFunction · 0.85
comprareOptionsFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected