2021-10-18 08:09:27 -04:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2023-09-07 21:40:02 -04:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-10-18 08:09:27 -04:00
|
|
|
|
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseUrl(t *testing.T) {
|
|
|
|
u, err := ParseURL("ssh://git@gitea.com:3000/gitea/tea")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "gitea.com:3000", u.Host)
|
|
|
|
assert.Equal(t, "ssh", u.Scheme)
|
|
|
|
assert.Equal(t, "/gitea/tea", u.Path)
|
|
|
|
|
|
|
|
u, err = ParseURL("https://gitea.com/gitea/tea")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "gitea.com", u.Host)
|
|
|
|
assert.Equal(t, "https", u.Scheme)
|
|
|
|
assert.Equal(t, "/gitea/tea", u.Path)
|
|
|
|
|
|
|
|
u, err = ParseURL("git@gitea.com:gitea/tea")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "gitea.com", u.Host)
|
|
|
|
assert.Equal(t, "ssh", u.Scheme)
|
|
|
|
assert.Equal(t, "/gitea/tea", u.Path)
|
|
|
|
|
|
|
|
u, err = ParseURL("gitea.com/gitea/tea")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "gitea.com", u.Host)
|
|
|
|
assert.Equal(t, "https", u.Scheme)
|
|
|
|
assert.Equal(t, "/gitea/tea", u.Path)
|
|
|
|
|
|
|
|
u, err = ParseURL("foo/bar")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "", u.Host)
|
|
|
|
assert.Equal(t, "", u.Scheme)
|
|
|
|
assert.Equal(t, "foo/bar", u.Path)
|
|
|
|
|
|
|
|
u, err = ParseURL("/foo/bar")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "", u.Host)
|
|
|
|
assert.Equal(t, "https", u.Scheme)
|
|
|
|
assert.Equal(t, "/foo/bar", u.Path)
|
|
|
|
|
|
|
|
// this case is unintuitive, but to ambiguous to be handled differently
|
|
|
|
u, err = ParseURL("gitea.com")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "", u.Host)
|
|
|
|
assert.Equal(t, "", u.Scheme)
|
|
|
|
assert.Equal(t, "gitea.com", u.Path)
|
|
|
|
}
|