diff --git a/pkg/git/gogit/transport.go b/pkg/git/gogit/transport.go index d30a2abd6..0ab3fbd67 100644 --- a/pkg/git/gogit/transport.go +++ b/pkg/git/gogit/transport.go @@ -17,6 +17,8 @@ limitations under the License. package gogit import ( + "fmt" + "github.com/go-git/go-git/v5/plumbing/transport" "github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/go-git/go-git/v5/plumbing/transport/ssh" @@ -53,6 +55,10 @@ func transportAuth(opts *git.AuthOptions) (transport.AuthMethod, error) { } return pk, nil } + case "": + return nil, fmt.Errorf("no transport type set") + default: + return nil, fmt.Errorf("unknown transport '%s'", opts.Transport) } return nil, nil } diff --git a/pkg/git/gogit/transport_test.go b/pkg/git/gogit/transport_test.go index f1863f0e8..93ea279d9 100644 --- a/pkg/git/gogit/transport_test.go +++ b/pkg/git/gogit/transport_test.go @@ -168,12 +168,16 @@ func Test_transportAuth(t *testing.T) { wantErr: errors.New("knownhosts: knownhosts: missing host pattern"), }, { - name: "Empty", - opts: &git.AuthOptions{}, - wantFunc: func(g *WithT, t transport.AuthMethod, opts *git.AuthOptions) { - g.Expect(t).To(BeNil()) + name: "Empty", + opts: &git.AuthOptions{}, + wantErr: errors.New("no transport type set"), + }, + { + name: "Unknown transport", + opts: &git.AuthOptions{ + Transport: "foo", }, - wantErr: nil, + wantErr: errors.New("unknown transport 'foo'"), }, } for _, tt := range tests {