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

Function TestCheckIssue

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

Source from the content-addressed store, hash-verified

675}
676
677func TestCheckIssue(t *testing.T) {
678 tests := []struct {
679 name string
680 number int
681 isPullRequest bool
682 lookupErr error
683 wantErr string
684 }{
685 {
686 name: "an issue",
687 number: 142,
688 },
689 {
690 name: "a pull request",
691 number: 158,
692 isPullRequest: true,
693 wantErr: "monalisa/monas-cafe#158 is a pull request; artifacts are only supported on issues",
694 },
695 {
696 name: "the lookup's error",
697 number: 999,
698 lookupErr: errors.New("GraphQL: Could not resolve to an issue or pull request with the number of 999. (repository.issue)"),
699 wantErr: "GraphQL: Could not resolve to an issue or pull request with the number of 999. (repository.issue)",
700 },
701 }
702
703 for _, tt := range tests {
704 t.Run(tt.name, func(t *testing.T) {
705 repo := ghrepo.New("monalisa", "monas-cafe")
706 mock := &client.ArtifactClientMock{
707 IsPullRequestFunc: func(ghrepo.Interface, int) (bool, error) {
708 return tt.isPullRequest, tt.lookupErr
709 },
710 }
711
712 err := CheckIssue(mock, repo, tt.number)
713
714 require.Len(t, mock.IsPullRequestCalls(), 1)
715 assert.Equal(t, repo, mock.IsPullRequestCalls()[0].Repo)
716 assert.Equal(t, tt.number, mock.IsPullRequestCalls()[0].Number)
717 if tt.wantErr != "" {
718 require.EqualError(t, err, tt.wantErr)
719 return
720 }
721 require.NoError(t, err)
722 })
723 }
724}
725
726func TestCheckUploadTarget(t *testing.T) {
727 tests := []struct {

Callers

nothing calls this directly

Calls 6

IsPullRequestCallsMethod · 0.95
NewFunction · 0.92
CheckIssueFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected