Rewritten streams creation

This commit is contained in:
Alexey Khit
2023-07-13 23:32:01 +03:00
parent eaef62a775
commit 85225917f5
10 changed files with 131 additions and 64 deletions
+26 -7
View File
@@ -1,19 +1,38 @@
package streams
import (
"github.com/stretchr/testify/require"
"net/url"
"testing"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/stretchr/testify/require"
)
func TestTemplate(t *testing.T) {
source1 := "does not matter"
stream1 := New("from_yaml", source1)
func TestRecursion(t *testing.T) {
// create stream with some source
stream1 := New("from_yaml", "does not matter")
require.Len(t, streams, 1)
stream2 := NewTemplate("camera.from_hass", "rtsp://localhost:8554/from_yaml?video")
// ask another unnamed stream that links go2rtc
query, err := url.ParseQuery("src=rtsp://localhost:8554/from_yaml?video")
require.Nil(t, err)
stream2 := GetOrPatch(query)
// check stream is same
require.Equal(t, stream1, stream2)
require.Equal(t, stream2.producers[0].url, source1)
// check stream urls is same
require.Equal(t, stream1.producers[0].url, stream2.producers[0].url)
require.Len(t, streams, 2)
}
func TestTempate(t *testing.T) {
HandleFunc("rtsp", func(url string) (core.Producer, error) { return nil, nil }) // bypass HasProducer
// config from yaml
stream1 := New("camera.from_hass", "ffmpeg:{input}#video=copy")
// request from hass
stream2 := Patch("camera.from_hass", "rtsp://example.com")
require.Equal(t, stream1, stream2)
require.Equal(t, "ffmpeg:rtsp://example.com#video=copy", stream1.producers[0].url)
}