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

Function TestNewUploader

pkg/cmd/issue/artifact/shared/shared_test.go:780–873  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

778}
779
780func TestNewUploader(t *testing.T) {
781 tests := []struct {
782 name string
783 repo ghrepo.Interface
784 number int
785 target *client.UploadTarget
786 lookupErr error
787 httpErr error
788 wantUpload bool
789 wantErr string
790 }{
791 {
792 name: "uploads against the issue's repository",
793 repo: ghrepo.New("monalisa", "monas-cafe"),
794 number: 142,
795 target: &client.UploadTarget{RepositoryID: 1234, ViewerPermission: "WRITE"},
796 wantUpload: true,
797 },
798 {
799 name: "uploads to a ghe.com host",
800 repo: ghrepo.NewWithHost("monalisa", "monas-cafe", "monas-cafe.ghe.com"),
801 number: 142,
802 target: &client.UploadTarget{RepositoryID: 1234, ViewerPermission: "MAINTAIN"},
803 wantUpload: true,
804 },
805 {
806 name: "a pull request",
807 repo: ghrepo.New("monalisa", "monas-cafe"),
808 number: 158,
809 target: &client.UploadTarget{IsPullRequest: true, RepositoryID: 1234, ViewerPermission: "WRITE"},
810 wantErr: "monalisa/monas-cafe#158 is a pull request; artifacts are only supported on issues",
811 },
812 {
813 name: "the lookup's error",
814 repo: ghrepo.New("monalisa", "monas-cafe"),
815 number: 999,
816 lookupErr: errors.New("GraphQL: Could not resolve to an issue or pull request with the number of 999. (repository.issue)"),
817 wantErr: "GraphQL: Could not resolve to an issue or pull request with the number of 999. (repository.issue)",
818 },
819 {
820 name: "without write access",
821 repo: ghrepo.New("monalisa", "monas-cafe"),
822 number: 142,
823 target: &client.UploadTarget{RepositoryID: 1234, ViewerPermission: "READ"},
824 wantErr: "attaching files requires write access to the repository",
825 },
826 {
827 name: "the HTTP client's error",
828 repo: ghrepo.New("monalisa", "monas-cafe"),
829 number: 142,
830 target: &client.UploadTarget{RepositoryID: 1234, ViewerPermission: "WRITE"},
831 httpErr: errors.New("no token"),
832 wantErr: "no token",
833 },
834 }
835
836 for _, tt := range tests {
837 t.Run(tt.name, func(t *testing.T) {

Callers

nothing calls this directly

Calls 12

VerifyMethod · 0.95
UploadTargetCallsMethod · 0.95
UploadAndAttachMethod · 0.95
NewFunction · 0.92
NewWithHostFunction · 0.92
NewTestAssetsFunction · 0.92
StubUploadToHostFunction · 0.92
EqualMethod · 0.80
NewUploaderFunction · 0.70
RunMethod · 0.65
RepoHostMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected