(t *testing.T)
| 58 | } |
| 59 | |
| 60 | func TestRecordQueryOne(t *testing.T) { |
| 61 | t.Parallel() |
| 62 | |
| 63 | app, _ := tests.NewTestApp() |
| 64 | defer app.Cleanup() |
| 65 | |
| 66 | scenarios := []struct { |
| 67 | name string |
| 68 | collection string |
| 69 | recordId string |
| 70 | model any |
| 71 | }{ |
| 72 | { |
| 73 | "record model", |
| 74 | "demo1", |
| 75 | "84nmscqy84lsi1t", |
| 76 | &core.Record{}, |
| 77 | }, |
| 78 | { |
| 79 | "record proxy", |
| 80 | "demo1", |
| 81 | "84nmscqy84lsi1t", |
| 82 | &struct { |
| 83 | core.BaseRecordProxy |
| 84 | }{}, |
| 85 | }, |
| 86 | { |
| 87 | "custom struct", |
| 88 | "demo1", |
| 89 | "84nmscqy84lsi1t", |
| 90 | &struct { |
| 91 | Id string `db:"id" json:"id"` |
| 92 | }{}, |
| 93 | }, |
| 94 | } |
| 95 | |
| 96 | for _, s := range scenarios { |
| 97 | t.Run(s.name, func(t *testing.T) { |
| 98 | collection, err := app.FindCollectionByNameOrId(s.collection) |
| 99 | if err != nil { |
| 100 | t.Fatal(err) |
| 101 | } |
| 102 | |
| 103 | q := app.RecordQuery(collection). |
| 104 | Where(dbx.HashExp{"id": s.recordId}) |
| 105 | |
| 106 | if err := q.One(s.model); err != nil { |
| 107 | t.Fatal(err) |
| 108 | } |
| 109 | |
| 110 | raw, err := json.Marshal(s.model) |
| 111 | if err != nil { |
| 112 | t.Fatal(err) |
| 113 | } |
| 114 | rawStr := string(raw) |
| 115 | |
| 116 | if !strings.Contains(rawStr, fmt.Sprintf(`"id":%q`, s.recordId)) { |
| 117 | t.Fatalf("Missing id %q in\n%s", s.recordId, rawStr) |
nothing calls this directly
no test coverage detected
searching dependent graphs…