MCPcopy
hub / github.com/lxc/incus / TestWithQuery

Function TestWithQuery

shared/api/url_test.go:215–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

213}
214
215func TestWithQuery(t *testing.T) {
216 tests := []struct {
217 name string
218 key string
219 value string
220 expectedKey string
221 expectedValue string
222 }{
223 {
224 name: "simple query",
225 key: "foo",
226 value: "bar",
227 expectedKey: "foo",
228 expectedValue: "bar",
229 },
230 {
231 name: "empty value",
232 key: "empty",
233 value: "",
234 expectedKey: "empty",
235 expectedValue: "",
236 },
237 }
238
239 for _, tt := range tests {
240 t.Run(tt.name, func(t *testing.T) {
241 u := NewURL().WithQuery(tt.key, tt.value)
242 query := u.Query()
243
244 if !query.Has(tt.expectedKey) {
245 t.Errorf("Expected query to have key %q", tt.expectedKey)
246 }
247
248 if query.Get(tt.expectedKey) != tt.expectedValue {
249 t.Errorf("Expected value %q for key %q, got %q", tt.expectedValue, tt.expectedKey, query.Get(tt.expectedKey))
250 }
251 })
252 }
253
254 // Test multiple query parameters
255 t.Run("multiple query parameters", func(t *testing.T) {
256 u := NewURL().
257 WithQuery("foo", "bar").
258 WithQuery("recursion", "1")
259
260 query := u.Query()
261 if query.Get("foo") != "bar" {
262 t.Errorf("Expected foo=bar, got %q", query.Get("filter"))
263 }
264
265 if query.Get("recursion") != "1" {
266 t.Errorf("Expected recursion=1, got %q", query.Get("recursion"))
267 }
268 })
269}
270
271func TestURLString(t *testing.T) {
272 tests := []struct {

Callers

nothing calls this directly

Calls 5

NewURLFunction · 0.85
WithQueryMethod · 0.80
ErrorfMethod · 0.80
GetMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…