(t *testing.T)
| 350 | } |
| 351 | |
| 352 | func TestRelationQuery(t *testing.T) { |
| 353 | t.Run("case=url encoding-decoding-encoding", func(t *testing.T) { |
| 354 | for i, tc := range []struct { |
| 355 | v url.Values |
| 356 | r *RelationQuery |
| 357 | }{ |
| 358 | { |
| 359 | v: url.Values{ |
| 360 | "namespace": []string{"n"}, |
| 361 | "object": []string{"o"}, |
| 362 | "relation": []string{"r"}, |
| 363 | "subject_id": []string{"foo"}, |
| 364 | }, |
| 365 | r: &RelationQuery{ |
| 366 | Namespace: new("n"), |
| 367 | Object: new("o"), |
| 368 | Relation: new("r"), |
| 369 | SubjectID: new("foo"), |
| 370 | }, |
| 371 | }, |
| 372 | { |
| 373 | v: url.Values{ |
| 374 | "namespace": []string{"n"}, |
| 375 | "object": []string{"o"}, |
| 376 | "relation": []string{"r"}, |
| 377 | "subject_set.namespace": []string{"sn"}, |
| 378 | "subject_set.object": []string{"so"}, |
| 379 | "subject_set.relation": []string{"sr"}, |
| 380 | }, |
| 381 | r: &RelationQuery{ |
| 382 | Namespace: new("n"), |
| 383 | Object: new("o"), |
| 384 | Relation: new("r"), |
| 385 | SubjectSet: &SubjectSet{ |
| 386 | Namespace: "sn", |
| 387 | Object: "so", |
| 388 | Relation: "sr", |
| 389 | }, |
| 390 | }, |
| 391 | }, |
| 392 | { |
| 393 | v: url.Values{ |
| 394 | "namespace": []string{"n"}, |
| 395 | "relation": []string{"r"}, |
| 396 | }, |
| 397 | r: &RelationQuery{ |
| 398 | Namespace: new("n"), |
| 399 | Relation: new("r"), |
| 400 | }, |
| 401 | }, |
| 402 | } { |
| 403 | t.Run(fmt.Sprintf("case=%d", i), func(t *testing.T) { |
| 404 | enc := tc.r.ToURLQuery() |
| 405 | assert.Equal(t, tc.v, enc) |
| 406 | |
| 407 | dec, err := (&RelationQuery{}).FromURLQuery(tc.v) |
| 408 | require.NoError(t, err) |
| 409 | assert.Equal(t, tc.r, dec) |
nothing calls this directly
no test coverage detected