1
Fork 0

Add test for groupBase.

This commit is contained in:
Juliusz Chroboczek 2024-02-24 12:27:19 +01:00
parent 017c004094
commit 6756e7f7cc
1 changed files with 58 additions and 1 deletions

View File

@ -1,8 +1,14 @@
package webserver
import (
"crypto/tls"
"encoding/json"
"net/http"
"os"
"path/filepath"
"testing"
"github.com/jech/galene/group"
"github.com/pion/webrtc/v3"
)
@ -30,6 +36,57 @@ func TestParseGroupName(t *testing.T) {
}
}
func TestBase(t *testing.T) {
a := []struct {
p string
t bool
h, res string
}{
{"", true, "a.org", "https://a.org/group/"},
{"", false, "a.org", "http://a.org/group/"},
{"https://b.org", true, "a.org", "https://b.org/group/"},
{"https://b.org", false, "a.org", "https://b.org/group/"},
{"http://b.org", true, "a.org", "http://b.org/group/"},
{"http://b.org", false, "a.org", "http://b.org/group/"},
}
dir := t.TempDir()
group.DataDirectory = dir
for _, v := range a {
conf := group.Configuration{
ProxyURL: v.p,
}
c, err := json.Marshal(conf)
if err != nil {
t.Errorf("Marshal: %v", err)
continue
}
err = os.WriteFile(
filepath.Join(dir, "config.json"),
c,
0600,
)
if err != nil {
t.Errorf("Write: %v", err)
continue
}
var tcs *tls.ConnectionState
if v.t {
tcs = &tls.ConnectionState{}
}
base, err := groupBase(&http.Request{
TLS: tcs,
Host: v.h,
})
if err != nil || base != v.res {
t.Errorf("Expected %v, got %v (%v)",
v.res, base, err,
)
}
}
}
func TestParseSplit(t *testing.T) {
a := []struct{ p, a, b, c string }{
{"", "", "", ""},
@ -43,7 +100,7 @@ func TestParseSplit(t *testing.T) {
{"/a/.b/c/d./", "/a", ".b", "/c/d./"},
}
for _, pabc := range(a) {
for _, pabc := range a {
a, b, c := splitPath(pabc.p)
if pabc.a != a || pabc.b != b || pabc.c != c {
t.Errorf("Path %v, got %v, %v, %v, expected %v, %v, %v",