MCPcopy
hub / github.com/pocketbase/pocketbase / TestPasswordFieldFindSetter

Function TestPasswordFieldFindSetter

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

Source from the content-addressed store, hash-verified

449}
450
451func 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 })

Callers

nothing calls this directly

Calls 8

SetRawMethod · 0.95
GetMethod · 0.95
NewBaseCollectionFunction · 0.92
NewRecordFunction · 0.92
FindSetterMethod · 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…