|
|
|
@ -2,6 +2,7 @@ package main
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"net" |
|
|
|
|
"os" |
|
|
|
|
"os/exec" |
|
|
|
|
"testing" |
|
|
|
@ -10,6 +11,41 @@ import (
@@ -10,6 +11,41 @@ import (
|
|
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ownDockerIp = func() string { |
|
|
|
|
out, err := exec.Command("docker", "network", "inspect", "bridge", |
|
|
|
|
"-f", "{{range .IPAM.Config}}{{.Subnet}}{{end}}").Output() |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_, ipnet, err := net.ParseCIDR(string(out[:len(out)-1])) |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ifaces, err := net.Interfaces() |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, i := range ifaces { |
|
|
|
|
addrs, err := i.Addrs() |
|
|
|
|
if err != nil { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, addr := range addrs { |
|
|
|
|
if v, ok := addr.(*net.IPNet); ok { |
|
|
|
|
if ipnet.Contains(v.IP) { |
|
|
|
|
return v.IP.String() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
panic("IP not found") |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
type container struct { |
|
|
|
|
name string |
|
|
|
|
stdout *bytes.Buffer |
|
|
|
@ -24,7 +60,7 @@ func newContainer(image string, name string, args []string) (*container, error)
@@ -24,7 +60,7 @@ func newContainer(image string, name string, args []string) (*container, error)
|
|
|
|
|
exec.Command("docker", "kill", "rtsp-simple-server-test-"+name).Run() |
|
|
|
|
exec.Command("docker", "wait", "rtsp-simple-server-test-"+name).Run() |
|
|
|
|
|
|
|
|
|
cmd := []string{"docker", "run", "--network=host", |
|
|
|
|
cmd := []string{"docker", "run", |
|
|
|
|
"--name=rtsp-simple-server-test-" + name, |
|
|
|
|
"rtsp-simple-server-test-" + image} |
|
|
|
|
cmd = append(cmd, args...) |
|
|
|
@ -76,7 +112,7 @@ func TestProtocols(t *testing.T) {
@@ -76,7 +112,7 @@ func TestProtocols(t *testing.T) {
|
|
|
|
|
"-c", "copy", |
|
|
|
|
"-f", "rtsp", |
|
|
|
|
"-rtsp_transport", pair[0], |
|
|
|
|
"rtsp://localhost:8554/teststream", |
|
|
|
|
"rtsp://" + ownDockerIp + ":8554/teststream", |
|
|
|
|
}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer cnt1.close() |
|
|
|
@ -87,7 +123,7 @@ func TestProtocols(t *testing.T) {
@@ -87,7 +123,7 @@ func TestProtocols(t *testing.T) {
|
|
|
|
|
"-hide_banner", |
|
|
|
|
"-loglevel", "panic", |
|
|
|
|
"-rtsp_transport", pair[1], |
|
|
|
|
"-i", "rtsp://localhost:8554/teststream", |
|
|
|
|
"-i", "rtsp://" + ownDockerIp + ":8554/teststream", |
|
|
|
|
"-vframes", "1", |
|
|
|
|
"-f", "image2", |
|
|
|
|
"-y", "/dev/null", |
|
|
|
@ -121,7 +157,7 @@ func TestPublishAuth(t *testing.T) {
@@ -121,7 +157,7 @@ func TestPublishAuth(t *testing.T) {
|
|
|
|
|
"-c", "copy", |
|
|
|
|
"-f", "rtsp", |
|
|
|
|
"-rtsp_transport", "udp", |
|
|
|
|
"rtsp://testuser:testpass@localhost:8554/teststream", |
|
|
|
|
"rtsp://testuser:testpass@" + ownDockerIp + ":8554/teststream", |
|
|
|
|
}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer cnt1.close() |
|
|
|
@ -132,7 +168,7 @@ func TestPublishAuth(t *testing.T) {
@@ -132,7 +168,7 @@ func TestPublishAuth(t *testing.T) {
|
|
|
|
|
"-hide_banner", |
|
|
|
|
"-loglevel", "panic", |
|
|
|
|
"-rtsp_transport", "udp", |
|
|
|
|
"-i", "rtsp://localhost:8554/teststream", |
|
|
|
|
"-i", "rtsp://" + ownDockerIp + ":8554/teststream", |
|
|
|
|
"-vframes", "1", |
|
|
|
|
"-f", "image2", |
|
|
|
|
"-y", "/dev/null", |
|
|
|
@ -164,7 +200,7 @@ func TestReadAuth(t *testing.T) {
@@ -164,7 +200,7 @@ func TestReadAuth(t *testing.T) {
|
|
|
|
|
"-c", "copy", |
|
|
|
|
"-f", "rtsp", |
|
|
|
|
"-rtsp_transport", "udp", |
|
|
|
|
"rtsp://localhost:8554/teststream", |
|
|
|
|
"rtsp://" + ownDockerIp + ":8554/teststream", |
|
|
|
|
}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer cnt1.close() |
|
|
|
@ -175,7 +211,7 @@ func TestReadAuth(t *testing.T) {
@@ -175,7 +211,7 @@ func TestReadAuth(t *testing.T) {
|
|
|
|
|
"-hide_banner", |
|
|
|
|
"-loglevel", "panic", |
|
|
|
|
"-rtsp_transport", "udp", |
|
|
|
|
"-i", "rtsp://testuser:testpass@localhost:8554/teststream", |
|
|
|
|
"-i", "rtsp://testuser:testpass@" + ownDockerIp + ":8554/teststream", |
|
|
|
|
"-vframes", "1", |
|
|
|
|
"-f", "image2", |
|
|
|
|
"-y", "/dev/null", |
|
|
|
|