github.com/abhinav/git-pr@v0.6.1-0.20171029234004-54218d68c11b/repo/guess_test.go (about)

     1  package repo
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/abhinav/git-pr/gateway/gatewaytest"
     7  
     8  	"github.com/golang/mock/gomock"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestGuess(t *testing.T) {
    13  	tests := []struct {
    14  		url string
    15  
    16  		want    Repo
    17  		wantErr string
    18  	}{
    19  		{url: "git@github.com:foo/bar", want: Repo{Owner: "foo", Name: "bar"}},
    20  		{url: "https://github.com/baz/qux", want: Repo{Owner: "baz", Name: "qux"}},
    21  		{url: "ssh://git@github.com/abc/def", want: Repo{Owner: "abc", Name: "def"}},
    22  		{url: "/home/foo/bar", wantErr: `remote "origin" (/home/foo/bar) is not a GitHub remote`},
    23  	}
    24  
    25  	for _, tt := range tests {
    26  		t.Run(tt.url, func(t *testing.T) {
    27  			mockCtrl := gomock.NewController(t)
    28  			defer mockCtrl.Finish()
    29  
    30  			git := gatewaytest.NewMockGit(mockCtrl)
    31  			git.EXPECT().RemoteURL("origin").Return(tt.url, nil).AnyTimes()
    32  
    33  			got, err := Guess(git)
    34  			if tt.wantErr != "" {
    35  				if assert.Error(t, err) {
    36  					assert.Contains(t, err.Error(), tt.wantErr)
    37  				}
    38  			} else {
    39  				assert.NoError(t, err)
    40  				assert.Equal(t, &tt.want, got)
    41  			}
    42  		})
    43  	}
    44  }