(t *testing.T)
| 720 | } |
| 721 | |
| 722 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…