MCPcopy
hub / github.com/livekit/livekit / TestAutoCreate

Function TestAutoCreate

test/singlenode_test.go:679–746  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

677}
678
679func TestAutoCreate(t *testing.T) {
680 if testing.Short() {
681 t.SkipNow()
682 return
683 }
684 disableAutoCreate := func(conf *config.Config) {
685 conf.Room.AutoCreate = false
686 }
687 t.Run("cannot join if room isn't created", func(t *testing.T) {
688 s := createSingleNodeServer(disableAutoCreate)
689 go func() {
690 if err := s.Start(); err != nil {
691 logger.Errorw("server returned error", err)
692 }
693 }()
694 defer s.Stop(true)
695
696 waitForServerToStart(s)
697
698 for _, testRTCServicePath := range testRTCServicePaths {
699 t.Run(fmt.Sprintf("testRTCServicePath=%s", testRTCServicePath.String()), func(t *testing.T) {
700 token := joinToken(testRoom, "start-before-create", nil)
701 opts := &testclient.Options{}
702 testRTCServicePathToTestClientOptions(testRTCServicePath, opts)
703 _, err := testclient.NewWebSocketConn(
704 fmt.Sprintf("ws://localhost:%d", defaultServerPort),
705 token,
706 opts,
707 )
708 require.Error(t, err)
709
710 // second join should also fail
711 token = joinToken(testRoom, "start-before-create-2", nil)
712 _, err = testclient.NewWebSocketConn(
713 fmt.Sprintf("ws://localhost:%d", defaultServerPort),
714 token,
715 opts,
716 )
717 require.Error(t, err)
718 })
719 }
720 })
721
722 t.Run("join with explicit createRoom", func(t *testing.T) {
723 s := createSingleNodeServer(disableAutoCreate)
724 go func() {
725 if err := s.Start(); err != nil {
726 logger.Errorw("server returned error", err)
727 }
728 }()
729 defer s.Stop(true)
730
731 waitForServerToStart(s)
732
733 // explicitly create
734 _, err := roomClient.CreateRoom(contextWithToken(createRoomToken()), &livekit.CreateRoomRequest{Name: testRoom})
735 require.NoError(t, err)
736

Callers

nothing calls this directly

Calls 13

createSingleNodeServerFunction · 0.85
waitForServerToStartFunction · 0.85
joinTokenFunction · 0.85
contextWithTokenFunction · 0.85
createRoomTokenFunction · 0.85
createRTCClientFunction · 0.85
waitUntilConnectedFunction · 0.85
StartMethod · 0.65
StopMethod · 0.65
CreateRoomMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected