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) {
return nil, fmt.Errorf("publish password must be alphanumeric") return nil, fmt.Errorf("publish password must be alphanumeric")
} }
} }
if len(pconf.PublishIps) > 0 {
pconf.PublishIpsParsed, err = parseIpCidrList(pconf.PublishIps) pconf.PublishIpsParsed, err = parseIpCidrList(pconf.PublishIps)
if err != nil { if err != nil {
return nil, err 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 != "" { if pconf.ReadUser != "" && pconf.ReadPass == "" || pconf.ReadUser == "" && pconf.ReadPass != "" {
return nil, fmt.Errorf("read username and password must be both filled") return nil, fmt.Errorf("read username and password must be both filled")
@ -347,10 +353,16 @@ func Load(fpath string) (*Conf, error) {
if pconf.ReadUser != "" && pconf.ReadPass == "" || pconf.ReadUser == "" && pconf.ReadPass != "" { if pconf.ReadUser != "" && pconf.ReadPass == "" || pconf.ReadUser == "" && pconf.ReadPass != "" {
return nil, fmt.Errorf("read username and password must be both filled") return nil, fmt.Errorf("read username and password must be both filled")
} }
if len(pconf.ReadIps) > 0 {
pconf.ReadIpsParsed, err = parseIpCidrList(pconf.ReadIps) pconf.ReadIpsParsed, err = parseIpCidrList(pconf.ReadIps)
if err != nil { if err != nil {
return nil, err 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 != "" { if pconf.Regexp != nil && pconf.RunOnInit != "" {
return nil, fmt.Errorf("a path with a regular expression does not support option 'runOnInit'; use another path") 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 (
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
"regexp"
"strconv" "strconv"
"testing" "testing"
"time" "time"
@ -143,11 +144,19 @@ func TestEnvironment(t *testing.T) {
os.Setenv("RTSP_PATHS_TEST2", "") os.Setenv("RTSP_PATHS_TEST2", "")
defer os.Unsetenv("RTSP_PATHS_TEST2") defer os.Unsetenv("RTSP_PATHS_TEST2")
// map value // map values, "all" path
os.Setenv("RTSP_PATHS_TEST_SOURCE", "rtsp://testing") os.Setenv("RTSP_PATHS_ALL_READUSER", "testuser")
defer os.Unsetenv("RTSP_PATHS_TEST_SOURCE") defer os.Unsetenv("RTSP_PATHS_ALL_READUSER")
os.Setenv("RTSP_PATHS_TEST_SOURCEPROTOCOL", "tcp") os.Setenv("RTSP_PATHS_ALL_READPASS", "testpass")
defer os.Unsetenv("RTSP_PATHS_TEST_SOURCEPROTOCOL") 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("") p, err := testProgram("")
require.NoError(t, err) require.NoError(t, err)
@ -169,7 +178,17 @@ func TestEnvironment(t *testing.T) {
Source: "record", Source: "record",
}, pa) }, 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, true, ok)
require.Equal(t, &conf.PathConf{ require.Equal(t, &conf.PathConf{
Source: "rtsp://testing", Source: "rtsp://testing",
@ -179,6 +198,7 @@ func TestEnvironment(t *testing.T) {
}(), }(),
SourceProtocol: "tcp", SourceProtocol: "tcp",
SourceProtocolParsed: gortsplib.StreamProtocolTCP, SourceProtocolParsed: gortsplib.StreamProtocolTCP,
SourceOnDemand: true,
}, pa) }, pa)
} }

Loading…
Cancel
Save