basic integration test

This commit is contained in:
David Zhao
2021-01-13 13:41:34 -08:00
parent 09e5a37c75
commit 233306d83a
6 changed files with 114 additions and 24 deletions
+47 -5
View File
@@ -3,22 +3,32 @@ package test
import (
"context"
"fmt"
"net/http"
"testing"
"time"
"github.com/livekit/livekit-server/cmd/cli/client"
"github.com/livekit/livekit-server/pkg/auth"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/service"
"github.com/livekit/livekit-server/proto/livekit"
)
const (
testApiKey = "apikey"
testApiSecret = "apiSecret"
testRoom = "mytestroom"
)
var (
serverConfig *config.Config
roomClient livekit.RoomService
)
func waitForServerToStart(s *service.LivekitServer) {
// wait till ready
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
for {
select {
case <-ctx.Done():
@@ -31,20 +41,51 @@ func waitForServerToStart(s *service.LivekitServer) {
}
}
func withTimeout(t *testing.T, f func() bool) {
ctx, _ := context.WithTimeout(context.Background(), time.Second)
for {
select {
case <-ctx.Done():
t.Fatal("timed out")
case <-time.After(10 * time.Millisecond):
if f() {
return
}
}
}
}
func createServer() *service.LivekitServer {
conf, err := config.NewConfig("")
var err error
serverConfig, err = config.NewConfig("")
if err != nil {
panic(fmt.Sprintf("could not create config: %v", err))
}
s, err := service.InitializeServer(conf, &StaticKeyProvider{})
s, err := service.InitializeServer(serverConfig, &StaticKeyProvider{})
if err != nil {
panic(fmt.Sprintf("could not create server: %v", err))
}
roomClient = livekit.NewRoomServiceJSONClient(fmt.Sprintf("http://localhost:%d", serverConfig.APIPort), &http.Client{})
return s
}
func createClient(room, name string) *client.RTCClient {
return nil
// creates a client and runs against server
func createClient(name string) *client.RTCClient {
token := joinToken(testRoom, name)
ws, err := client.NewWebSocketConn(fmt.Sprintf("ws://localhost:%d", serverConfig.RTCPort), token)
if err != nil {
panic(err)
}
c, err := client.NewRTCClient(ws)
if err != nil {
panic(err)
}
go c.Run()
return c
}
func joinToken(room, name string) string {
@@ -78,6 +119,7 @@ func (p *StaticKeyProvider) NumKeys() int {
func (p *StaticKeyProvider) GetSecret(key string) string {
if key == testApiKey {
logger.GetLogger().Debugf("returning secret: %s", testApiSecret)
return testApiSecret
}
return ""