github.com/abhinav/git-fu@v0.6.1-0.20171029234004-54218d68c11b/github/gateway_test.go (about)

     1  package github
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/abhinav/git-pr/gateway"
     9  	"github.com/abhinav/git-pr/ptr"
    10  
    11  	"github.com/golang/mock/gomock"
    12  	"github.com/google/go-github/github"
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  func TestListPullRequestReviews(t *testing.T) {
    17  	tests := []struct {
    18  		give []*github.PullRequestReview
    19  		want []*gateway.PullRequestReview
    20  	}{
    21  		{give: nil, want: []*gateway.PullRequestReview{}},
    22  		{
    23  			give: []*github.PullRequestReview{
    24  				{
    25  					State: ptr.String("APPROVED"),
    26  					User:  &github.User{Login: ptr.String("foo")},
    27  				},
    28  				{
    29  					State: ptr.String("CHANGES_REQUESTED"),
    30  					User:  &github.User{Login: ptr.String("bar")},
    31  				},
    32  			},
    33  			want: []*gateway.PullRequestReview{
    34  				{User: "foo", Status: gateway.PullRequestApproved},
    35  				{User: "bar", Status: gateway.PullRequestChangesRequested},
    36  			},
    37  		},
    38  	}
    39  
    40  	for i, tt := range tests {
    41  		t.Run(fmt.Sprint(i), func(t *testing.T) {
    42  			mockCtrl := gomock.NewController(t)
    43  			defer mockCtrl.Finish()
    44  
    45  			prService := NewMockPullRequestsService(mockCtrl)
    46  			prService.EXPECT().
    47  				ListReviews(gomock.Any(), "foo", "bar", 42).
    48  				Return(tt.give, &github.Response{}, nil)
    49  
    50  			gw := Gateway{
    51  				owner: "foo",
    52  				repo:  "bar",
    53  				pulls: prService,
    54  			}
    55  
    56  			gotReviews, err := gw.ListPullRequestReviews(context.Background(), 42)
    57  			require.NoError(t, err)
    58  			require.Equal(t, tt.want, gotReviews)
    59  		})
    60  	}
    61  }