mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package rtmp
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestToken(t *testing.T) {
|
|
data := [][]string{
|
|
{"/foo/bar", "/foo", "bar"},
|
|
{"/foo/bar?token=abc", "/foo/bar", "abc"},
|
|
{"/foo/bar/abc", "/foo/bar", "abc"},
|
|
{"/foo/bar/&!'", "/foo/bar", "&!'"},
|
|
{"/foo/bar/%26%21%27", "/foo/bar", "&!'"},
|
|
}
|
|
|
|
for _, d := range data {
|
|
u, err := url.Parse(d[0])
|
|
require.NoError(t, err)
|
|
|
|
path, token, _ := GetToken(u)
|
|
|
|
require.Equal(t, d[1], path, "url=%s", u.String())
|
|
require.Equal(t, d[2], token, "url=%s", u.String())
|
|
}
|
|
}
|
|
|
|
func TestSplitPath(t *testing.T) {
|
|
data := map[string][]string{
|
|
"/foo/bar": {"foo", "bar"},
|
|
"foo/bar": {"foo", "bar"},
|
|
"/foo/bar/": {"foo", "bar"},
|
|
}
|
|
|
|
for path, split := range data {
|
|
elms := splitPath(path)
|
|
|
|
require.ElementsMatch(t, split, elms, "%s", path)
|
|
}
|
|
}
|
|
|
|
func TestRemovePathPrefix(t *testing.T) {
|
|
data := [][]string{
|
|
{"/foo/bar", "/foo", "/bar"},
|
|
{"/foo/bar", "/fo", "/foo/bar"},
|
|
{"/foo/bar/abc", "/foo/bar", "/abc"},
|
|
}
|
|
|
|
for _, d := range data {
|
|
x, _ := removePathPrefix(d[0], d[1])
|
|
|
|
require.Equal(t, d[2], x, "path=%s prefix=%s", d[0], d[1])
|
|
}
|
|
}
|