(t *testing.T)
| 724 | } |
| 725 | |
| 726 | func TestCheckUploadTarget(t *testing.T) { |
| 727 | tests := []struct { |
| 728 | name string |
| 729 | number int |
| 730 | target *client.UploadTarget |
| 731 | lookupErr error |
| 732 | want *client.UploadTarget |
| 733 | wantErr string |
| 734 | }{ |
| 735 | { |
| 736 | name: "an issue", |
| 737 | number: 142, |
| 738 | target: &client.UploadTarget{RepositoryID: 1234, ViewerPermission: "WRITE"}, |
| 739 | want: &client.UploadTarget{RepositoryID: 1234, ViewerPermission: "WRITE"}, |
| 740 | }, |
| 741 | { |
| 742 | name: "a pull request", |
| 743 | number: 158, |
| 744 | target: &client.UploadTarget{IsPullRequest: true, RepositoryID: 1234, ViewerPermission: "WRITE"}, |
| 745 | wantErr: "monalisa/monas-cafe#158 is a pull request; artifacts are only supported on issues", |
| 746 | }, |
| 747 | { |
| 748 | name: "the lookup's error", |
| 749 | number: 999, |
| 750 | lookupErr: errors.New("GraphQL: Could not resolve to an issue or pull request with the number of 999. (repository.issue)"), |
| 751 | wantErr: "GraphQL: Could not resolve to an issue or pull request with the number of 999. (repository.issue)", |
| 752 | }, |
| 753 | } |
| 754 | |
| 755 | for _, tt := range tests { |
| 756 | t.Run(tt.name, func(t *testing.T) { |
| 757 | repo := ghrepo.New("monalisa", "monas-cafe") |
| 758 | mock := &client.ArtifactClientMock{ |
| 759 | UploadTargetFunc: func(ghrepo.Interface, int) (*client.UploadTarget, error) { |
| 760 | return tt.target, tt.lookupErr |
| 761 | }, |
| 762 | } |
| 763 | |
| 764 | got, err := CheckUploadTarget(mock, repo, tt.number) |
| 765 | |
| 766 | require.Len(t, mock.UploadTargetCalls(), 1) |
| 767 | assert.Equal(t, repo, mock.UploadTargetCalls()[0].Repo) |
| 768 | assert.Equal(t, tt.number, mock.UploadTargetCalls()[0].Number) |
| 769 | if tt.wantErr != "" { |
| 770 | require.EqualError(t, err, tt.wantErr) |
| 771 | assert.Nil(t, got) |
| 772 | return |
| 773 | } |
| 774 | require.NoError(t, err) |
| 775 | assert.Equal(t, tt.want, got) |
| 776 | }) |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | func TestNewUploader(t *testing.T) { |
| 781 | tests := []struct { |
nothing calls this directly
no test coverage detected