github.com/livekit/protocol@v1.16.1-0.20240517185851-47e4c6bba773/egress/types_test.go (about)

     1  package egress
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/livekit/protocol/livekit"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestGetOutputType(t *testing.T) {
    11  	roomReq := &livekit.RoomCompositeEgressRequest{
    12  		FileOutputs: []*livekit.EncodedFileOutput{
    13  			&livekit.EncodedFileOutput{},
    14  		},
    15  	}
    16  
    17  	ot := GetOutputType(roomReq)
    18  	require.Equal(t, OutputTypeFile, ot)
    19  
    20  	roomReq = &livekit.RoomCompositeEgressRequest{
    21  		Output: &livekit.RoomCompositeEgressRequest_File{
    22  			File: &livekit.EncodedFileOutput{},
    23  		},
    24  	}
    25  
    26  	ot = GetOutputType(roomReq)
    27  	require.Equal(t, OutputTypeFile, ot)
    28  
    29  	trackReq := &livekit.TrackCompositeEgressRequest{
    30  		SegmentOutputs: []*livekit.SegmentedFileOutput{
    31  			&livekit.SegmentedFileOutput{},
    32  		},
    33  	}
    34  
    35  	ot = GetOutputType(trackReq)
    36  	require.Equal(t, OutputTypeSegments, ot)
    37  
    38  	trackReq = &livekit.TrackCompositeEgressRequest{
    39  		Output: &livekit.TrackCompositeEgressRequest_Segments{
    40  			Segments: &livekit.SegmentedFileOutput{},
    41  		},
    42  	}
    43  
    44  	ot = GetOutputType(trackReq)
    45  	require.Equal(t, OutputTypeSegments, ot)
    46  
    47  	webReq := &livekit.WebEgressRequest{
    48  		StreamOutputs: []*livekit.StreamOutput{
    49  			&livekit.StreamOutput{},
    50  		},
    51  	}
    52  
    53  	ot = GetOutputType(webReq)
    54  	require.Equal(t, OutputTypeStream, ot)
    55  
    56  	webReq = &livekit.WebEgressRequest{
    57  		Output: &livekit.WebEgressRequest_Stream{
    58  			Stream: &livekit.StreamOutput{},
    59  		},
    60  	}
    61  
    62  	ot = GetOutputType(webReq)
    63  	require.Equal(t, OutputTypeStream, ot)
    64  
    65  	participantReq := &livekit.ParticipantEgressRequest{
    66  		ImageOutputs: []*livekit.ImageOutput{
    67  			&livekit.ImageOutput{},
    68  		},
    69  	}
    70  
    71  	ot = GetOutputType(participantReq)
    72  	require.Equal(t, OutputTypeImages, ot)
    73  
    74  	participantReq.SegmentOutputs = []*livekit.SegmentedFileOutput{
    75  		&livekit.SegmentedFileOutput{},
    76  	}
    77  
    78  	ot = GetOutputType(participantReq)
    79  	require.Equal(t, OutputTypeMultiple, ot)
    80  
    81  }