MCPcopy
hub / github.com/ory/keto / TestNewHandler

Function TestNewHandler

schema/handler_test.go:28–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestNewHandler(t *testing.T) {
29 r := httprouterx.NewTestRouterPublic(t)
30 reg := driver.NewSqliteTestRegistry(t, false)
31 h := schema.NewHandler(reg)
32 h.RegisterSyntaxRoutes(r)
33 ts := httptest.NewServer(r)
34 t.Cleanup(ts.Close)
35
36 t.Run("proto=REST", func(t *testing.T) {
37 t.Run("method=POST /opl/syntax/check", func(t *testing.T) {
38 response, err := ts.Client().Post(
39 ts.URL+"/opl/syntax/check",
40 "text/plain",
41 bytes.NewBufferString("/* comment???"))
42 require.NoError(t, err)
43 require.Equal(t, http.StatusOK, response.StatusCode)
44 body, err := io.ReadAll(response.Body)
45 require.NoError(t, err)
46 t.Log(string(body))
47 assert.Contains(t, gjson.GetBytes(body, "errors.0.message").String(), "unclosed comment")
48 })
49 })
50
51 t.Run("proto=gRPC", func(t *testing.T) {
52 l := bufconn.Listen(1024 * 1024)
53 s := grpc.NewServer()
54 h.RegisterSyntaxGRPC(s)
55 go func() {
56 if err := s.Serve(l); err != nil {
57 t.Logf("Server exited with error: %v", err)
58 }
59 }()
60 t.Cleanup(s.Stop)
61
62 conn, err := grpc.NewClient("passthrough:///bufnet",
63 grpc.WithTransportCredentials(insecure.NewCredentials()),
64 grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { return l.Dial() }),
65 )
66 require.NoError(t, err)
67
68 client := opl.NewSyntaxServiceClient(conn)
69
70 t.Run("method=Syntax.Check", func(t *testing.T) {
71 response, err := client.Check(t.Context(), &opl.CheckRequest{
72 Content: []byte("/* comment???"),
73 })
74 require.NoError(t, err)
75 assert.Contains(t, response.ParseErrors[0].Message, "unclosed comment")
76 })
77 })
78}

Callers

nothing calls this directly

Calls 10

RegisterSyntaxRoutesMethod · 0.95
RegisterSyntaxGRPCMethod · 0.95
CheckMethod · 0.95
NewSqliteTestRegistryFunction · 0.92
NewHandlerFunction · 0.92
NewServerMethod · 0.80
ServeMethod · 0.80
ClientMethod · 0.65
StringMethod · 0.65
LogfMethod · 0.45

Tested by

no test coverage detected