MCPcopy
hub / github.com/ent/ent / TestHasNeighborsWithContext

Function TestHasNeighborsWithContext

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

Source from the content-addressed store, hash-verified

886}
887
888func TestHasNeighborsWithContext(t *testing.T) {
889 type key string
890 ctx := context.WithValue(context.Background(), key("mykey"), "myval")
891 for _, rel := range [...]Rel{M2M, O2M, O2O} {
892 t.Run(rel.String(), func(t *testing.T) {
893 sel := sql.Dialect(dialect.Postgres).
894 Select("*").
895 From(sql.Table("users")).
896 WithContext(ctx)
897 step := NewStep(
898 From("users", "id"),
899 To("groups", "id"),
900 Edge(rel, false, "user_groups", "user_id", "group_id"),
901 )
902 var called bool
903 pred := func(s *sql.Selector) {
904 called = true
905 got := s.Context().Value(key("mykey")).(string)
906 require.Equal(t, "myval", got)
907 }
908 HasNeighborsWith(sel, step, pred)
909 require.True(t, called, "expected predicate function to be called")
910 })
911 }
912}
913
914func TestOrderByNeighborsCount(t *testing.T) {
915 build := sql.Dialect(dialect.Postgres)

Callers

nothing calls this directly

Calls 15

DialectFunction · 0.92
TableFunction · 0.92
NewStepFunction · 0.85
HasNeighborsWithFunction · 0.85
RunMethod · 0.80
WithContextMethod · 0.80
ContextMethod · 0.80
keyTypeAlias · 0.70
FromFunction · 0.70
ToFunction · 0.70
EdgeFunction · 0.70
ValueMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…