Files
Roger 3e9150249c refactor: rename core types and spell out every name (#677)
Def, Request, DirID, and Source said too little, and short variables and doc comments that skip their name hid intent.
varnamelen and staticcheck ST1020-22 now keep both from coming back.
2026-11-02 11:06:05 +08:00

92 lines
1.8 KiB
Go

package safari
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuildURL(t *testing.T) {
tests := []struct {
name string
protocol string
server string
port uint32
path string
want string
}{
{
name: "https default port",
protocol: "htps",
server: "github.com",
port: 443,
want: "https://github.com",
},
{
name: "https custom port",
protocol: "htps",
server: "example.com",
port: 8443,
want: "https://example.com:8443",
},
{
name: "http with path",
protocol: "http",
server: "192.168.1.1",
port: 80,
path: "/admin",
want: "http://192.168.1.1/admin",
},
{
name: "http non-default port",
protocol: "http",
server: "localhost",
port: 8080,
want: "http://localhost:8080",
},
{
name: "empty server returns empty",
protocol: "htps",
server: "",
port: 443,
want: "",
},
{
name: "empty protocol defaults to https",
protocol: "",
server: "example.com",
port: 0,
want: "https://example.com",
},
{
name: "smb protocol",
protocol: "smb ",
server: "fileserver",
port: 445,
want: "smb://fileserver:445",
},
{
name: "ftp default port",
protocol: "ftp ",
server: "ftp.example.com",
port: 21,
want: "ftp://ftp.example.com",
},
{
name: "root path ignored",
protocol: "htps",
server: "example.com",
port: 443,
path: "/",
want: "https://example.com",
},
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
got := buildURL(testCase.protocol, testCase.server, testCase.port, testCase.path)
assert.Equal(t, testCase.want, got)
})
}
}