mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-27 12:56:54 +01:00
b868d30434
Co-authored-by: techknowlogick <hello@techknowlogick.com> Co-committed-by: techknowlogick <hello@techknowlogick.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
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)
|
|
}
|