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

Function TestCommitServiceV1ReturnsProtobuf

internal/connect/api_test.go:316–361  ·  view source on GitHub ↗

--- Handler content-type tests ---

(t *testing.T)

Source from the content-addressed store, hash-verified

314// --- Handler content-type tests ---
315
316func TestCommitServiceV1ReturnsProtobuf(t *testing.T) {
317 p := &mockProvider{
318 meta: content.Meta{
319 Commit: "deadbeef",
320 DefaultBranch: "main",
321 },
322 files: []content.File{
323 {Path: "test.proto", Data: []byte("syntax = \"proto3\";"), Hash: shake256.Hash{}},
324 },
325 }
326 mux := testMux(p)
327 server := httptest.NewServer(mux)
328 defer server.Close()
329
330 for _, path := range []string{
331 "/buf.registry.module.v1.CommitService/GetCommits",
332 "/buf.registry.module.v1beta1.CommitService/GetCommits",
333 } {
334 t.Run(path, func(t *testing.T) {
335 body := buildGetCommitsRequest("owner", "repo")
336 resp, err := http.Post(server.URL+path, "application/proto", bytes.NewReader(body))
337 if err != nil {
338 t.Fatalf("request failed: %v", err)
339 }
340 defer resp.Body.Close()
341
342 if ct := resp.Header.Get("Content-Type"); ct != "application/proto" {
343 t.Errorf("Content-Type = %q, want %q", ct, "application/proto")
344 }
345 if resp.StatusCode != http.StatusOK {
346 respBody, _ := io.ReadAll(resp.Body)
347 t.Fatalf("status = %d, want 200; body: %s", resp.StatusCode, respBody)
348 }
349
350 respBody, _ := io.ReadAll(resp.Body)
351 if len(respBody) == 0 {
352 t.Fatal("empty response body")
353 }
354 // Verify it's valid protobuf: should start with field tag
355 _, _, n := protowire.ConsumeTag(respBody)
356 if n < 0 {
357 t.Fatalf("response is not valid protobuf: %x", respBody[:min(len(respBody), 32)])
358 }
359 })
360 }
361}
362
363func TestGraphServiceV1ReturnsProtobuf(t *testing.T) {
364 p := &mockProvider{

Callers

nothing calls this directly

Calls 3

testMuxFunction · 0.85
buildGetCommitsRequestFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected