github.com/abhinav/git-pr@v0.6.1-0.20171029234004-54218d68c11b/repo/parse_test.go (about) 1 package repo 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestParse(t *testing.T) { 10 tests := []struct { 11 give string 12 want Repo 13 wantErr string 14 }{ 15 { 16 give: "foo/bar", 17 want: Repo{Owner: "foo", Name: "bar"}, 18 }, 19 { 20 give: "foobar", 21 wantErr: "repository must be in the form owner/repo", 22 }, 23 { 24 give: "/foo", 25 wantErr: `owner in repository "/foo" cannot be empty`, 26 }, 27 { 28 give: "foo/", 29 wantErr: `name in repository "foo/" cannot be empty`, 30 }, 31 } 32 33 for _, tt := range tests { 34 t.Run(tt.give, func(t *testing.T) { 35 got, err := Parse(tt.give) 36 if tt.wantErr != "" { 37 if assert.Error(t, err) { 38 assert.Contains(t, err.Error(), tt.wantErr) 39 } 40 } else { 41 assert.NoError(t, err) 42 assert.Equal(t, &tt.want, got) 43 assert.Equal(t, tt.give, got.String()) 44 } 45 }) 46 } 47 }