mirror of
https://github.com/go-gitea/gitea
synced 2024-11-05 09:44:26 +00:00
e81ccc406b
Change all license headers to comply with REUSE specification. Fix #16132 Co-authored-by: flynnnnnnnnnn <flynnnnnnnnnn@github> Co-authored-by: John Olheiser <john.olheiser@gmail.com>
58 lines
993 B
Go
58 lines
993 B
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"net/url"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFileURLToPath(t *testing.T) {
|
|
cases := []struct {
|
|
url string
|
|
expected string
|
|
haserror bool
|
|
windows bool
|
|
}{
|
|
// case 0
|
|
{
|
|
url: "",
|
|
haserror: true,
|
|
},
|
|
// case 1
|
|
{
|
|
url: "http://test.io",
|
|
haserror: true,
|
|
},
|
|
// case 2
|
|
{
|
|
url: "file:///path",
|
|
expected: "/path",
|
|
},
|
|
// case 3
|
|
{
|
|
url: "file:///C:/path",
|
|
expected: "C:/path",
|
|
windows: true,
|
|
},
|
|
}
|
|
|
|
for n, c := range cases {
|
|
if c.windows && runtime.GOOS != "windows" {
|
|
continue
|
|
}
|
|
u, _ := url.Parse(c.url)
|
|
p, err := FileURLToPath(u)
|
|
if c.haserror {
|
|
assert.Error(t, err, "case %d: should return error", n)
|
|
} else {
|
|
assert.NoError(t, err, "case %d: should not return error", n)
|
|
assert.Equal(t, c.expected, p, "case %d: should be equal", n)
|
|
}
|
|
}
|
|
}
|