MCPcopy
hub / github.com/alibaba/MongoShake / TestEncodeMongoURI

Function TestEncodeMongoURI

common/community_client_test.go:134–211  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestEncodeMongoURI(t *testing.T) {
135 tests := []struct {
136 input string
137 expected string
138 err string
139 }{
140 {
141 input: "mongodb://root:password001@localhost:27017/admin",
142 expected: "mongodb://root:password001@localhost:27017/admin",
143 err: "",
144 },
145 {
146 input: "mongodb://root:1234@abcd@localhost:27017/admin",
147 expected: "mongodb://root:1234%40abcd@localhost:27017/admin",
148 err: "",
149 },
150 {
151 input: "mongodb://root:dUM3!k&TdofokP0yl1@dds-xxx1.mongodb.rds.aliyuncs.com:3717,dds-xxx2.mongodb.rds.aliyuncs.com:3717",
152 expected: "mongodb://root:dUM3%21k&TdofokP0yl1@dds-xxx1.mongodb.rds.aliyuncs.com:3717,dds-xxx2.mongodb.rds.aliyuncs.com:3717",
153 err: "",
154 },
155 {
156 input: "mongodb://root_special_char:MongoDB@%()!#&-=@localhost:27017/admin",
157 expected: "mongodb://root_special_char:MongoDB%40%25%28%29%21%23&-=@localhost:27017/admin",
158 err: "",
159 },
160 {
161 input: "mongodb://root_special_char1:~!@#$^&*()_-=@localhost:27017/admin",
162 expected: "mongodb://root_special_char1:~%21%40%23$%5E&%2A%28%29_-=@localhost:27017/admin",
163 err: "",
164 },
165 {
166 input: "mongodb://user:pass@localhost/db",
167 expected: "mongodb://user:pass@localhost/db",
168 err: "",
169 },
170 {
171 input: "mongodb://user:pass:@localhost/db",
172 expected: "mongodb://user:pass%3A@localhost/db",
173 err: "",
174 },
175 {
176 input: "mongodb://user:passwd@localhost:27017",
177 expected: "mongodb://user:passwd@localhost:27017",
178 err: "",
179 },
180 {
181 input: "mongodb://localhost:27017,localhost:27018",
182 expected: "mongodb://localhost:27017,localhost:27018",
183 err: "",
184 },
185 {
186 input: "invalid://user:pass@host/db",
187 err: "unsupported scheme: invalid",
188 },
189 {
190 input: "mongodb://user@host/db",
191 err: "missing ':' in username:password",

Callers

nothing calls this directly

Calls 3

EncodeMongoURIFunction · 0.85
ErrorMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected