MCPcopy Create free account
hub / github.com/cli/cli / TestMutableSafeURLSetQuery

Function TestMutableSafeURLSetQuery

internal/safeurl/safeurl_test.go:256–293  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

254}
255
256func TestMutableSafeURLSetQuery(t *testing.T) {
257 type query struct {
258 key string
259 value string
260 }
261
262 tests := []struct {
263 name string
264 queries []query
265 want string
266 }{
267 {
268 name: "replaces existing value rather than appending",
269 queries: []query{{"a", "1"}, {"a", "2"}},
270 want: "foo/bar?a=2",
271 },
272 {
273 name: "sorts keys deterministically",
274 queries: []query{{"b", "2"}, {"a", "1"}},
275 want: "foo/bar?a=1&b=2",
276 },
277 {
278 name: "escapes keys and values",
279 queries: []query{{"a", "x y&z"}},
280 want: "foo/bar?a=x+y%26z",
281 },
282 }
283 for _, tt := range tests {
284 t.Run(tt.name, func(t *testing.T) {
285 u, err := safeurl.JoinPath("foo", "bar")
286 require.NoError(t, err)
287 for _, q := range tt.queries {
288 u.SetQuery(q.key, q.value)
289 }
290 require.Equal(t, tt.want, u.String())
291 })
292 }
293}
294
295func TestImmutableSafeURLString(t *testing.T) {
296 tests := []struct {

Callers

nothing calls this directly

Calls 5

JoinPathFunction · 0.92
SetQueryMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected