mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-05-30 00:49:44 +00:00
- Ported unit tests for WB Stream, SaluteJazz, and Telemost API clients - Ported engine helper tests for SaluteJazz and Goolom - Fixed missing WB Stream WebSocket URL update (wss://rtc-el-01.wb.ru) - Corrected SaluteJazz header casing (X-Jazz-AuthType) - Fixed linting errors (goconst, gosec, lll) in test files
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package telemost
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func withTelemostAPIServer(t *testing.T, h http.Handler) {
|
|
t.Helper()
|
|
old := apiBase
|
|
srv := httptest.NewServer(h)
|
|
t.Cleanup(func() {
|
|
apiBase = old
|
|
srv.Close()
|
|
})
|
|
apiBase = srv.URL
|
|
}
|
|
|
|
func TestGetConnectionInfo(t *testing.T) {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("GET /conferences/{id...}", func(w http.ResponseWriter, r *http.Request) {
|
|
if !strings.HasPrefix(r.URL.Path, "/conferences/room/id/connection") {
|
|
t.Fatalf("path = %q", r.URL.Path)
|
|
}
|
|
if r.URL.Query().Get("display_name") != "peer" {
|
|
t.Fatalf("display_name query = %q", r.URL.Query().Get("display_name"))
|
|
}
|
|
_ = json.NewEncoder(w).Encode(ConnectionInfo{
|
|
RoomID: "room",
|
|
PeerID: "peer-id",
|
|
Credentials: "creds",
|
|
})
|
|
})
|
|
|
|
withTelemostAPIServer(t, mux)
|
|
|
|
info, err := GetConnectionInfo(context.Background(), "room/id", "peer")
|
|
if err != nil {
|
|
t.Fatalf("GetConnectionInfo() error = %v", err)
|
|
}
|
|
if info.RoomID != "room" || info.PeerID != "peer-id" || info.Credentials != "creds" {
|
|
t.Fatalf("GetConnectionInfo() = %+v", info)
|
|
}
|
|
}
|
|
|
|
func TestGetConnectionInfoErrors(t *testing.T) {
|
|
withTelemostAPIServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
http.Error(w, "bad", http.StatusForbidden)
|
|
}))
|
|
if _, err := GetConnectionInfo(context.Background(), "room", "peer"); !errors.Is(err, ErrAPI) {
|
|
t.Fatalf("GetConnectionInfo() error = %v, want %v", err, ErrAPI)
|
|
}
|
|
|
|
withTelemostAPIServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
_, _ = w.Write([]byte("{"))
|
|
}))
|
|
if _, err := GetConnectionInfo(context.Background(), "room", "peer"); err == nil {
|
|
t.Fatal("GetConnectionInfo() unexpectedly accepted bad json")
|
|
}
|
|
}
|