Skip to content

Commit ea35389

Browse files
authored
Merge pull request #174 from stanhu/sh-add-prelude-unit-tests
2 parents 9ea5a1f + 6e90db5 commit ea35389

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

test/redis_client/config_test.rb

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,46 @@ def test_ipv6_uri
6464
assert_equal "::1", config.host
6565
end
6666

67-
def test_user_password_uri
67+
def test_resp2_user_password_uri
68+
config = Config.new(protocol: 2, url: "redis://username:[email protected]")
69+
assert_equal "example.com", config.host
70+
assert_equal 6379, config.port
71+
assert_equal "username", config.username
72+
assert_equal "password", config.password
73+
assert_equal 0, config.db
74+
refute_predicate config, :ssl?
75+
assert_equal [%w[AUTH username password]], config.connection_prelude
76+
end
77+
78+
def test_resp3_user_password_uri
6879
config = Config.new(url: "redis://username:[email protected]")
6980
assert_equal "example.com", config.host
7081
assert_equal 6379, config.port
7182
assert_equal "username", config.username
7283
assert_equal "password", config.password
7384
assert_equal 0, config.db
7485
refute_predicate config, :ssl?
86+
assert_equal [%w[HELLO 3 AUTH username password]], config.connection_prelude
7587
end
7688

77-
def test_frozen_prelude
89+
def test_resp2_frozen_prelude
90+
config = Config.new(protocol: 2, url: "redis://username:[email protected]")
91+
prelude = config.connection_prelude
92+
93+
assert_equal [%w[AUTH username password]], prelude
94+
assert_equal true, prelude.frozen?
95+
assert_equal true, (prelude.all? { |commands| commands.frozen? })
96+
97+
prelude.each do |commands|
98+
assert_equal true, (commands.all? { |arg| arg.frozen? })
99+
end
100+
end
101+
102+
def test_resp3_frozen_prelude
78103
config = Config.new(url: "redis://username:[email protected]")
79104
prelude = config.connection_prelude
105+
106+
assert_equal [%w[HELLO 3 AUTH username password]], prelude
80107
assert_equal true, prelude.frozen?
81108
assert_equal true, (prelude.all? { |commands| commands.frozen? })
82109

@@ -85,14 +112,26 @@ def test_frozen_prelude
85112
end
86113
end
87114

88-
def test_simple_password_uri
115+
def test_resp2_simple_password_uri
116+
config = Config.new(protocol: 2, url: "redis://[email protected]")
117+
assert_equal "example.com", config.host
118+
assert_equal 6379, config.port
119+
assert_equal "default", config.username
120+
assert_equal "password", config.password
121+
assert_equal 0, config.db
122+
refute_predicate config, :ssl?
123+
assert_equal [%w[AUTH password]], config.connection_prelude
124+
end
125+
126+
def test_resp3_simple_password_uri
89127
config = Config.new(url: "redis://[email protected]")
90128
assert_equal "example.com", config.host
91129
assert_equal 6379, config.port
92130
assert_equal "default", config.username
93131
assert_equal "password", config.password
94132
assert_equal 0, config.db
95133
refute_predicate config, :ssl?
134+
assert_equal [%w[HELLO 3 AUTH default password]], config.connection_prelude
96135
end
97136

98137
def test_simple_password_uri_empty_user
@@ -103,6 +142,7 @@ def test_simple_password_uri_empty_user
103142
assert_equal "password", config.password
104143
assert_equal 0, config.db
105144
refute_predicate config, :ssl?
145+
assert_equal [%w[HELLO 3 AUTH default password]], config.connection_prelude
106146
end
107147

108148
def test_percent_encoded_password_uri
@@ -114,6 +154,7 @@ def test_percent_encoded_password_uri
114154
assert_equal "p@ssw0rd", config.password
115155
assert_equal 12, config.db
116156
refute_predicate config, :ssl?
157+
assert_equal [%w[HELLO 3 AUTH default p@ssw0rd], %w[SELECT 12]], config.connection_prelude
117158
end
118159

119160
def test_rediss_url
@@ -124,13 +165,16 @@ def test_rediss_url
124165
assert_nil config.password
125166
assert_equal 0, config.db
126167
assert_predicate config, :ssl?
168+
assert_equal [%w[HELLO 3]], config.connection_prelude
127169
end
128170

129171
def test_trailing_slash_url
130172
config = Config.new(url: "redis://example.com/")
131173
assert_equal 0, config.db
174+
assert_equal [%w[HELLO 3]], config.connection_prelude
132175
config = Config.new(url: "redis://[::1]/")
133176
assert_equal 0, config.db
177+
assert_equal [%w[HELLO 3]], config.connection_prelude
134178
end
135179

136180
def test_overriding
@@ -150,6 +194,7 @@ def test_overriding
150194
assert_equal "hunter2", config.password
151195
assert_equal 5, config.db
152196
assert_predicate config, :ssl?
197+
assert_equal [%w[HELLO 3 AUTH george hunter2], %w[SELECT 5]], config.connection_prelude
153198
end
154199

155200
def test_server_url

0 commit comments

Comments
 (0)