MCPcopy Index your code
hub / github.com/ent/ent / TestQueryEdgesSchema

Function TestQueryEdgesSchema

dialect/sql/sqlgraph/graph_test.go:2563–2599  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2561}
2562
2563func TestQueryEdgesSchema(t *testing.T) {
2564 db, mock, err := sqlmock.New()
2565 require.NoError(t, err)
2566 mock.ExpectQuery(escape("SELECT `group_id`, `user_id` FROM `mydb`.`user_groups` WHERE `user_id` IN (?, ?, ?)")).
2567 WithArgs(1, 2, 3).
2568 WillReturnRows(sqlmock.NewRows([]string{"group_id", "user_id"}).
2569 AddRow(4, 5).
2570 AddRow(4, 6))
2571
2572 var (
2573 edges [][]int64
2574 spec = &EdgeQuerySpec{
2575 Edge: &EdgeSpec{
2576 Inverse: true,
2577 Table: "user_groups",
2578 Schema: "mydb",
2579 Columns: []string{"user_id", "group_id"},
2580 },
2581 Predicate: func(s *sql.Selector) {
2582 s.Where(sql.InValues("user_id", 1, 2, 3))
2583 },
2584 ScanValues: func() [2]any {
2585 return [2]any{&sql.NullInt64{}, &sql.NullInt64{}}
2586 },
2587 Assign: func(out, in any) error {
2588 o, i := out.(*sql.NullInt64), in.(*sql.NullInt64)
2589 edges = append(edges, []int64{o.Int64, i.Int64})
2590 return nil
2591 },
2592 }
2593 )
2594
2595 // Query and scan.
2596 err = QueryEdges(context.Background(), sql.OpenDB("", db), spec)
2597 require.NoError(t, err)
2598 require.Equal(t, [][]int64{{4, 5}, {4, 6}}, edges)
2599}
2600
2601func TestIsConstraintError(t *testing.T) {
2602 tests := []struct {

Callers

nothing calls this directly

Calls 6

InValuesFunction · 0.92
OpenDBFunction · 0.92
QueryEdgesFunction · 0.85
NewMethod · 0.80
escapeFunction · 0.70
WhereMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…