(t *testing.T)
| 449 | } |
| 450 | |
| 451 | func TestPasswordFieldFindSetter(t *testing.T) { |
| 452 | scenarios := []struct { |
| 453 | name string |
| 454 | key string |
| 455 | value any |
| 456 | field *core.PasswordField |
| 457 | hasSetter bool |
| 458 | expected string |
| 459 | }{ |
| 460 | { |
| 461 | "no match", |
| 462 | "example", |
| 463 | "abc", |
| 464 | &core.PasswordField{Name: "test"}, |
| 465 | false, |
| 466 | "", |
| 467 | }, |
| 468 | { |
| 469 | "exact match", |
| 470 | "test", |
| 471 | "abc", |
| 472 | &core.PasswordField{Name: "test"}, |
| 473 | true, |
| 474 | `"abc"`, |
| 475 | }, |
| 476 | } |
| 477 | |
| 478 | for _, s := range scenarios { |
| 479 | t.Run(s.name, func(t *testing.T) { |
| 480 | collection := core.NewBaseCollection("test_collection") |
| 481 | collection.Fields.Add(s.field) |
| 482 | |
| 483 | setter := s.field.FindSetter(s.key) |
| 484 | |
| 485 | hasSetter := setter != nil |
| 486 | if hasSetter != s.hasSetter { |
| 487 | t.Fatalf("Expected hasSetter %v, got %v", s.hasSetter, hasSetter) |
| 488 | } |
| 489 | |
| 490 | if !hasSetter { |
| 491 | return |
| 492 | } |
| 493 | |
| 494 | record := core.NewRecord(collection) |
| 495 | record.SetRaw(s.field.GetName(), []string{"c", "d"}) |
| 496 | |
| 497 | setter(record, s.value) |
| 498 | |
| 499 | raw, err := json.Marshal(record.Get(s.field.GetName())) |
| 500 | if err != nil { |
| 501 | t.Fatal(err) |
| 502 | } |
| 503 | rawStr := string(raw) |
| 504 | |
| 505 | if rawStr != s.expected { |
| 506 | t.Fatalf("Expected %q, got %q", s.expected, rawStr) |
| 507 | } |
| 508 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…