MCPcopy Create free account
hub / github.com/easyp-tech/server / TestGraphServiceV1ReturnsProtobuf

Function TestGraphServiceV1ReturnsProtobuf

internal/connect/api_test.go:363–418  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

361}
362
363func TestGraphServiceV1ReturnsProtobuf(t *testing.T) {
364 p := &mockProvider{
365 meta: content.Meta{
366 Commit: "cafe1234",
367 DefaultBranch: "main",
368 },
369 files: []content.File{
370 {Path: "graph.proto", Data: []byte("syntax = \"proto3\";"), Hash: shake256.Hash{}},
371 },
372 }
373 mux := testMux(p)
374 server := httptest.NewServer(mux)
375 defer server.Close()
376
377 // Pre-populate commit cache via CommitService so GraphService can look it up.
378 commitResp, err := http.Post(
379 server.URL+"/buf.registry.module.v1.CommitService/GetCommits",
380 "application/proto",
381 bytes.NewReader(buildGetCommitsRequest("owner", "repo")),
382 )
383 if err != nil {
384 t.Fatalf("pre-seed CommitService request failed: %v", err)
385 }
386 io.ReadAll(commitResp.Body)
387 commitResp.Body.Close()
388
389 testPaths := []struct {
390 path string
391 body []byte
392 }{
393 {"/buf.registry.module.v1.GraphService/GetGraph", buildV1GetGraphRequest("owner", "repo")},
394 {"/buf.registry.module.v1beta1.GraphService/GetGraph", buildGetGraphRequest("owner", "repo")},
395 }
396 for _, tc := range testPaths {
397 t.Run(tc.path, func(t *testing.T) {
398 resp, err := http.Post(server.URL+tc.path, "application/proto", bytes.NewReader(tc.body))
399 if err != nil {
400 t.Fatalf("request failed: %v", err)
401 }
402 defer resp.Body.Close()
403
404 if ct := resp.Header.Get("Content-Type"); ct != "application/proto" {
405 t.Errorf("Content-Type = %q, want %q", ct, "application/proto")
406 }
407 if resp.StatusCode != http.StatusOK {
408 respBody, _ := io.ReadAll(resp.Body)
409 t.Fatalf("status = %d, want 200; body: %s", resp.StatusCode, respBody)
410 }
411
412 respBody, _ := io.ReadAll(resp.Body)
413 if len(respBody) == 0 {
414 t.Fatal("empty response body")
415 }
416 })
417 }
418}
419
420func TestDownloadServiceV1ReturnsProtobuf(t *testing.T) {

Callers

nothing calls this directly

Calls 5

testMuxFunction · 0.85
buildGetCommitsRequestFunction · 0.85
buildV1GetGraphRequestFunction · 0.85
buildGetGraphRequestFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected