MCPcopy
hub / github.com/pocketbase/pocketbase / TestPasswordFieldFindGetter

Function TestPasswordFieldFindGetter

core/field_password_test.go:512–569  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

510}
511
512func 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}

Callers

nothing calls this directly

Calls 7

SetRawMethod · 0.95
NewBaseCollectionFunction · 0.92
NewRecordFunction · 0.92
FindGetterMethod · 0.65
GetNameMethod · 0.65
RunMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…