MCPcopy Create free account
hub / github.com/cli/cli / TestFetchBlob

Function TestFetchBlob

internal/skills/discovery/discovery_test.go:722–778  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

720}
721
722func TestFetchBlob(t *testing.T) {
723 tests := []struct {
724 name string
725 stubs func(*httpmock.Registry)
726 wantErr string
727 want string
728 }{
729 {
730 name: "decodes base64 content",
731 stubs: func(reg *httpmock.Registry) {
732 reg.Register(
733 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/blobs/abc"),
734 httpmock.JSONResponse(map[string]interface{}{
735 "sha": "abc", "encoding": "base64", "content": "SGVsbG8gV29ybGQ=",
736 }))
737 },
738 want: "Hello World",
739 },
740 {
741 name: "rejects non-base64 encoding",
742 stubs: func(reg *httpmock.Registry) {
743 reg.Register(
744 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/blobs/abc"),
745 httpmock.JSONResponse(map[string]interface{}{
746 "sha": "abc", "encoding": "utf-8", "content": "raw",
747 }))
748 },
749 wantErr: "unexpected blob encoding: utf-8",
750 },
751 {
752 name: "API error",
753 stubs: func(reg *httpmock.Registry) {
754 reg.Register(
755 httpmock.REST("GET", "repos/monalisa/octocat-skills/git/blobs/abc"),
756 httpmock.StatusStringResponse(500, "server error"))
757 },
758 wantErr: "could not fetch blob",
759 },
760 }
761 for _, tt := range tests {
762 t.Run(tt.name, func(t *testing.T) {
763 reg := &httpmock.Registry{}
764 defer reg.Verify(t)
765 tt.stubs(reg)
766 client := api.NewClientFromHTTP(&http.Client{Transport: reg})
767
768 got, err := FetchBlob(client, "github.com", "monalisa", "octocat-skills", "abc")
769 if tt.wantErr != "" {
770 require.Error(t, err)
771 assert.Contains(t, err.Error(), tt.wantErr)
772 return
773 }
774 require.NoError(t, err)
775 assert.Equal(t, tt.want, got)
776 })
777 }
778}
779

Callers

nothing calls this directly

Calls 11

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
JSONResponseFunction · 0.92
StatusStringResponseFunction · 0.92
NewClientFromHTTPFunction · 0.92
FetchBlobFunction · 0.85
ContainsMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…