MCPcopy
hub / github.com/dosco/graphjin / TestGraphQLRoleQueryMultipleRowsError

Function TestGraphQLRoleQueryMultipleRowsError

core/role_query_graphql_test.go:68–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestGraphQLRoleQueryMultipleRowsError(t *testing.T) {
69 db := newGraphQLRoleTestDB(t)
70 defer db.Close() //nolint:errcheck
71
72 conf := &core.Config{
73 DBType: "sqlite",
74 DisableAllowList: true,
75 RolesQuery: `query {
76 users(where: { id: { gt: $user_id } }) {
77 userid: id
78 }
79 }`,
80 Roles: []core.Role{
81 {Name: "admin", Match: "userid = 1"},
82 },
83 }
84
85 gj, err := core.NewGraphJin(conf, db)
86 if err != nil {
87 t.Fatal(err)
88 }
89 defer gj.Close()
90
91 ctx := context.WithValue(context.Background(), core.UserIDKey, 0)
92 _, err = gj.GraphQL(ctx, `{ users(id: 1) { id } }`, nil, nil)
93 if err == nil {
94 t.Fatal("GraphQL() expected multiple rows error")
95 }
96 if !strings.Contains(err.Error(), "roles_query returned multiple rows") {
97 t.Fatalf("GraphQL() error = %v, want multiple rows roles_query error", err)
98 }
99}
100
101func TestGraphQLRoleQueryMalformedMatchErrorsAtInit(t *testing.T) {
102 db := newGraphQLRoleTestDB(t)

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
GraphQLMethod · 0.95
newGraphQLRoleTestDBFunction · 0.85
CloseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected