add more environment tests

This commit is contained in:
aler9 2020-10-19 00:08:44 +02:00
parent 113cbe602c
commit 64e38f7db4
2 changed files with 44 additions and 12 deletions

View file

@ -326,9 +326,15 @@ func Load(fpath string) (*Conf, error) {
return nil, fmt.Errorf("publish password must be alphanumeric")
}
}
pconf.PublishIpsParsed, err = parseIpCidrList(pconf.PublishIps)
if err != nil {
return nil, err
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 != "" {
@ -347,9 +353,15 @@ 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")
}
pconf.ReadIpsParsed, err = parseIpCidrList(pconf.ReadIps)
if err != nil {
return nil, err
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 != "" {

View file

@ -6,6 +6,7 @@ import (
"net/url"
"os"
"os/exec"
"regexp"
"strconv"
"testing"
"time"
@ -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) {
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) {
}(),
SourceProtocol: "tcp",
SourceProtocolParsed: gortsplib.StreamProtocolTCP,
SourceOnDemand: true,
}, pa)
}