MCPcopy Index your code
hub / github.com/authorizerdev/authorizer / TestRESTMeta

Function TestRESTMeta

internal/integration_tests/rest_meta_test.go:25–69  ·  view source on GitHub ↗

TestRESTMeta exercises GET /v1/meta through the grpc-gateway. Validates that the gateway translates the REST call into an in-process gRPC invocation against AuthorizerService.Meta, then renders the response as JSON. The response is the flat Meta object (no wrapper), byte-identical to the GraphQL `me

(t *testing.T)

Source from the content-addressed store, hash-verified

23// JSON. The response is the flat Meta object (no wrapper), byte-identical to
24// the GraphQL `meta` query response.
25func TestRESTMeta(t *testing.T) {
26 cfg := getTestConfig()
27 cfg.ClientID = "test-client"
28
29 log := zerolog.New(zerolog.NewTestWriter(t)).With().Timestamp().Logger()
30
31 svc, err := service.New(cfg, &service.Dependencies{Log: &log})
32 require.NoError(t, err)
33
34 grpcSrv, err := grpcsrv.New(":0", &grpcsrv.Dependencies{
35 Log: &log,
36 Config: cfg,
37 ServiceProvider: svc,
38 TokenProvider: nil,
39 })
40 require.NoError(t, err)
41
42 ctx, cancel := context.WithCancel(context.Background())
43 t.Cleanup(cancel)
44 gw, cleanup, err := gateway.Handler(ctx, grpcSrv.GRPCServer())
45 require.NoError(t, err)
46 t.Cleanup(cleanup)
47
48 gin.SetMode(gin.TestMode)
49 r := gin.New()
50 r.Any("/v1/*path", gin.WrapH(gw))
51 ts := httptest.NewServer(r)
52 t.Cleanup(ts.Close)
53
54 resp, err := http.Get(ts.URL + "/v1/meta")
55 require.NoError(t, err)
56 defer func() { _ = resp.Body.Close() }()
57 require.Equal(t, http.StatusOK, resp.StatusCode)
58
59 body, err := io.ReadAll(resp.Body)
60 require.NoError(t, err)
61
62 var got struct {
63 ClientID string `json:"client_id"`
64 Version string `json:"version"`
65 }
66 require.NoError(t, json.Unmarshal(body, &got))
67 require.Equal(t, "test-client", got.ClientID)
68 require.NotEmpty(t, got.Version)
69}

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
NewFunction · 0.92
HandlerFunction · 0.92
getTestConfigFunction · 0.85
GRPCServerMethod · 0.80
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected