MCPcopy
hub / github.com/pocketbase/pocketbase / TestFieldsListStringAndValue

Function TestFieldsListStringAndValue

core/fields_list_test.go:397–450  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

395}
396
397func TestFieldsListStringAndValue(t *testing.T) {
398 t.Run("empty list", func(t *testing.T) {
399 testFieldsList := core.NewFieldsList()
400
401 str := testFieldsList.String()
402 if str != "[]" {
403 t.Fatalf("Expected empty slice, got\n%q", str)
404 }
405
406 v, err := testFieldsList.Value()
407 if err != nil {
408 t.Fatal(err)
409 }
410 if v != str {
411 t.Fatalf("Expected String and Value to match")
412 }
413 })
414
415 t.Run("list with fields", func(t *testing.T) {
416 testFieldsList := core.NewFieldsList(
417 &core.TextField{Id: "f1id", Name: "test1"},
418 &core.BoolField{Id: "f2id", Name: "test2"},
419 &core.URLField{Id: "f3id", Name: "test3"},
420 )
421
422 str := testFieldsList.String()
423
424 v, err := testFieldsList.Value()
425 if err != nil {
426 t.Fatal(err)
427 }
428 if v != str {
429 t.Fatalf("Expected String and Value to match")
430 }
431
432 expectedParts := []string{
433 `"type":"bool"`,
434 `"type":"url"`,
435 `"type":"text"`,
436 `"id":"f1id"`,
437 `"id":"f2id"`,
438 `"id":"f3id"`,
439 `"name":"test1"`,
440 `"name":"test2"`,
441 `"name":"test3"`,
442 }
443
444 for _, part := range expectedParts {
445 if !strings.Contains(str, part) {
446 t.Fatalf("Missing %q in\nn%v", part, str)
447 }
448 }
449 })
450}
451
452func TestFieldsListScan(t *testing.T) {
453 scenarios := []struct {

Callers

nothing calls this directly

Calls 4

StringMethod · 0.95
ValueMethod · 0.95
NewFieldsListFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…