Browse Source

add more environment tests

pull/169/head
aler9 5 years ago
parent
commit
64e38f7db4
  1. 12
      conf/conf.go
  2. 32
      main_test.go

12
conf/conf.go

@ -326,10 +326,16 @@ func Load(fpath string) (*Conf, error) { @@ -326,10 +326,16 @@ func Load(fpath string) (*Conf, error) {
return nil, fmt.Errorf("publish password must be alphanumeric")
}
}
if len(pconf.PublishIps) > 0 {
pconf.PublishIpsParsed, err = parseIpCidrList(pconf.PublishIps)
if err != nil {
return nil, err
}
} else {
// yaml doesn't use nil dicts - avoid test fails by using nil
pconf.PublishIps = nil
}
if pconf.ReadUser != "" && pconf.ReadPass == "" || pconf.ReadUser == "" && pconf.ReadPass != "" {
return nil, fmt.Errorf("read username and password must be both filled")
@ -347,10 +353,16 @@ func Load(fpath string) (*Conf, error) { @@ -347,10 +353,16 @@ func Load(fpath string) (*Conf, error) {
if pconf.ReadUser != "" && pconf.ReadPass == "" || pconf.ReadUser == "" && pconf.ReadPass != "" {
return nil, fmt.Errorf("read username and password must be both filled")
}
if len(pconf.ReadIps) > 0 {
pconf.ReadIpsParsed, err = parseIpCidrList(pconf.ReadIps)
if err != nil {
return nil, err
}
} else {
// yaml doesn't use nil dicts - avoid test fails by using nil
pconf.ReadIps = nil
}
if pconf.Regexp != nil && pconf.RunOnInit != "" {
return nil, fmt.Errorf("a path with a regular expression does not support option 'runOnInit'; use another path")

32
main_test.go

@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
"net/url"
"os"
"os/exec"
"regexp"
"strconv"
"testing"
"time"
@ -143,11 +144,19 @@ func TestEnvironment(t *testing.T) { @@ -143,11 +144,19 @@ func TestEnvironment(t *testing.T) {
os.Setenv("RTSP_PATHS_TEST2", "")
defer os.Unsetenv("RTSP_PATHS_TEST2")
// map value
os.Setenv("RTSP_PATHS_TEST_SOURCE", "rtsp://testing")
defer os.Unsetenv("RTSP_PATHS_TEST_SOURCE")
os.Setenv("RTSP_PATHS_TEST_SOURCEPROTOCOL", "tcp")
defer os.Unsetenv("RTSP_PATHS_TEST_SOURCEPROTOCOL")
// map values, "all" path
os.Setenv("RTSP_PATHS_ALL_READUSER", "testuser")
defer os.Unsetenv("RTSP_PATHS_ALL_READUSER")
os.Setenv("RTSP_PATHS_ALL_READPASS", "testpass")
defer os.Unsetenv("RTSP_PATHS_ALL_READPASS")
// map values, generic path
os.Setenv("RTSP_PATHS_CAM1_SOURCE", "rtsp://testing")
defer os.Unsetenv("RTSP_PATHS_CAM1_SOURCE")
os.Setenv("RTSP_PATHS_CAM1_SOURCEPROTOCOL", "tcp")
defer os.Unsetenv("RTSP_PATHS_CAM1_SOURCEPROTOCOL")
os.Setenv("RTSP_PATHS_CAM1_SOURCEONDEMAND", "yes")
defer os.Unsetenv("RTSP_PATHS_CAM1_SOURCEONDEMAND")
p, err := testProgram("")
require.NoError(t, err)
@ -169,7 +178,17 @@ func TestEnvironment(t *testing.T) { @@ -169,7 +178,17 @@ func TestEnvironment(t *testing.T) {
Source: "record",
}, pa)
pa, ok = p.conf.Paths["test"]
pa, ok = p.conf.Paths["~^.*$"]
require.Equal(t, true, ok)
require.Equal(t, &conf.PathConf{
Regexp: regexp.MustCompile("^.*$"),
Source: "record",
SourceProtocol: "udp",
ReadUser: "testuser",
ReadPass: "testpass",
}, pa)
pa, ok = p.conf.Paths["cam1"]
require.Equal(t, true, ok)
require.Equal(t, &conf.PathConf{
Source: "rtsp://testing",
@ -179,6 +198,7 @@ func TestEnvironment(t *testing.T) { @@ -179,6 +198,7 @@ func TestEnvironment(t *testing.T) {
}(),
SourceProtocol: "tcp",
SourceProtocolParsed: gortsplib.StreamProtocolTCP,
SourceOnDemand: true,
}, pa)
}

Loading…
Cancel
Save