refactoring to prep for integration tests
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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/service"
|
||||
)
|
||||
|
||||
const (
|
||||
testApiKey = "apikey"
|
||||
testApiSecret = "apiSecret"
|
||||
)
|
||||
|
||||
func waitForServerToStart(s *service.LivekitServer) {
|
||||
// wait till ready
|
||||
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
panic("could not start server after timeout")
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
if s.IsRunning() {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func createServer() *service.LivekitServer {
|
||||
conf, err := config.NewConfig("")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("could not create config: %v", err))
|
||||
}
|
||||
s, err := service.InitializeServer(conf, &StaticKeyProvider{})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("could not create server: %v", err))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func createClient(room, name string) *client.RTCClient {
|
||||
return nil
|
||||
}
|
||||
|
||||
func joinToken(room, name string) string {
|
||||
at := auth.NewAccessToken(testApiKey, testApiSecret).
|
||||
AddGrant(&auth.VideoGrant{RoomJoin: true, Room: room}).
|
||||
SetIdentity(name)
|
||||
t, err := at.ToJWT()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func createRoomToken() string {
|
||||
at := auth.NewAccessToken(testApiKey, testApiSecret).
|
||||
AddGrant(&auth.VideoGrant{RoomCreate: true}).
|
||||
SetIdentity("testuser")
|
||||
t, err := at.ToJWT()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
type StaticKeyProvider struct {
|
||||
}
|
||||
|
||||
func (p *StaticKeyProvider) NumKeys() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (p *StaticKeyProvider) GetSecret(key string) string {
|
||||
if key == testApiKey {
|
||||
return testApiSecret
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestScenarioDefault(t *testing.T) {
|
||||
assert.True(t, true)
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
s := createServer()
|
||||
go func() {
|
||||
s.Start()
|
||||
}()
|
||||
|
||||
waitForServerToStart(s)
|
||||
|
||||
code := m.Run()
|
||||
|
||||
s.Stop()
|
||||
os.Exit(code)
|
||||
}
|
||||
Reference in New Issue
Block a user