(t *testing.T)
| 510 | } |
| 511 | |
| 512 | func TestPasswordFieldFindGetter(t *testing.T) { |
| 513 | scenarios := []struct { |
| 514 | name string |
| 515 | key string |
| 516 | field *core.PasswordField |
| 517 | hasGetter bool |
| 518 | expected string |
| 519 | }{ |
| 520 | { |
| 521 | "no match", |
| 522 | "example", |
| 523 | &core.PasswordField{Name: "test"}, |
| 524 | false, |
| 525 | "", |
| 526 | }, |
| 527 | { |
| 528 | "field name match", |
| 529 | "test", |
| 530 | &core.PasswordField{Name: "test"}, |
| 531 | true, |
| 532 | "test_plain", |
| 533 | }, |
| 534 | { |
| 535 | "field name hash modifier", |
| 536 | "test:hash", |
| 537 | &core.PasswordField{Name: "test"}, |
| 538 | true, |
| 539 | "test_hash", |
| 540 | }, |
| 541 | } |
| 542 | |
| 543 | for _, s := range scenarios { |
| 544 | t.Run(s.name, func(t *testing.T) { |
| 545 | collection := core.NewBaseCollection("test_collection") |
| 546 | collection.Fields.Add(s.field) |
| 547 | |
| 548 | getter := s.field.FindGetter(s.key) |
| 549 | |
| 550 | hasGetter := getter != nil |
| 551 | if hasGetter != s.hasGetter { |
| 552 | t.Fatalf("Expected hasGetter %v, got %v", s.hasGetter, hasGetter) |
| 553 | } |
| 554 | |
| 555 | if !hasGetter { |
| 556 | return |
| 557 | } |
| 558 | |
| 559 | record := core.NewRecord(collection) |
| 560 | record.SetRaw(s.field.GetName(), &core.PasswordFieldValue{Hash: "test_hash", Plain: "test_plain"}) |
| 561 | |
| 562 | result := getter(record) |
| 563 | |
| 564 | if result != s.expected { |
| 565 | t.Fatalf("Expected %q, got %#v", s.expected, result) |
| 566 | } |
| 567 | }) |
| 568 | } |
| 569 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…