device: use constants for test code

This commit is contained in:
Scott 2020-01-31 12:22:48 +10:30
parent a123789cac
commit 9ddd4be089
5 changed files with 57 additions and 26 deletions

View File

@ -110,15 +110,20 @@ func TestNearestPowerOfTwo(t *testing.T) {
}
func TestIsRunning(t *testing.T) {
const dur = 250 * time.Millisecond
const sampleRate = 1000
const channels = 1
const bitDepth = 16
const recPeriod = 1
l := logger.New(logger.Debug, &bytes.Buffer{}, true) // Discard logs.
d := New(l)
var err error
err = d.Set(config.Config{
SampleRate: 1000,
Channels: 1,
BitDepth: 16,
RecPeriod: 1,
err := d.Set(config.Config{
SampleRate: sampleRate,
Channels: channels,
BitDepth: bitDepth,
RecPeriod: recPeriod,
InputCodec: codecutil.ADPCM,
})
if err != nil {
@ -129,7 +134,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Skipf("could not start device %w", err)
}
time.Sleep(250 * time.Millisecond)
time.Sleep(dur)
if !d.IsRunning() {
t.Error("device isn't running, when it should be")
}
@ -138,7 +145,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Error(err.Error())
}
time.Sleep(250 * time.Millisecond)
time.Sleep(dur)
if d.IsRunning() {
t.Error("device is running, when it should not be")
}

View File

@ -32,11 +32,13 @@ import (
)
func TestIsRunning(t *testing.T) {
const dur = 250 * time.Millisecond
const path = "../../../test/test-data/av/input/motion-detection/mjpeg/school.mjpeg"
d := New()
var err error
d.Set(config.Config{
InputPath: "../../../test/test-data/av/input/motion-detection/mjpeg/school.mjpeg",
err := d.Set(config.Config{
InputPath: path,
})
if err != nil {
t.Skipf("could not set device: %w", err)
@ -46,7 +48,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Skipf("could not start device %w", err)
}
time.Sleep(250 * time.Millisecond)
time.Sleep(dur)
if !d.IsRunning() {
t.Error("device isn't running, when it should be")
}
@ -55,7 +59,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Error(err.Error())
}
time.Sleep(250 * time.Millisecond)
time.Sleep(dur)
if d.IsRunning() {
t.Error("device is running, when it should not be")
}

View File

@ -35,14 +35,16 @@ import (
)
func TestIsRunning(t *testing.T) {
const dur = 250 * time.Millisecond
const ip = "192.168.4.20"
l := logger.New(logger.Debug, &bytes.Buffer{}, true) // Discard logs.
d := New(l)
var err error
d.Set(config.Config{
err := d.Set(config.Config{
Logger: l,
InputCodec: codecutil.H264,
CameraIP: "192.168.4.20",
CameraIP: ip,
})
if err != nil {
t.Skipf("could not set device: %w", err)
@ -52,7 +54,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Skipf("could not start device %w", err)
}
time.Sleep(50 * time.Millisecond)
time.Sleep(dur)
if !d.IsRunning() {
t.Error("device isn't running, when it should be")
}
@ -61,7 +65,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Error(err.Error())
}
time.Sleep(50 * time.Millisecond)
time.Sleep(dur)
if d.IsRunning() {
t.Error("device is running, when it should not be")
}

View File

@ -34,11 +34,12 @@ import (
)
func TestIsRunning(t *testing.T) {
const dur = 250 * time.Millisecond
l := logger.New(logger.Debug, &bytes.Buffer{}, true) // Discard logs.
d := New(l)
var err error
d.Set(config.Config{
err := d.Set(config.Config{
Logger: l,
InputCodec: codecutil.H264,
})
@ -50,7 +51,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Skipf("could not start device %w", err)
}
time.Sleep(250 * time.Millisecond)
time.Sleep(dur)
if !d.IsRunning() {
t.Error("device isn't running, when it should be")
}
@ -59,7 +62,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Error(err.Error())
}
time.Sleep(250 * time.Millisecond)
time.Sleep(dur)
if d.IsRunning() {
t.Error("device is running, when it should not be")
}

View File

@ -34,11 +34,12 @@ import (
)
func TestIsRunning(t *testing.T) {
const dur = 250 * time.Millisecond
l := logger.New(logger.Debug, &bytes.Buffer{}, true) // Discard logs.
d := New(l)
var err error
d.Set(config.Config{
err := d.Set(config.Config{
Logger: l,
InputCodec: codecutil.H264,
})
@ -50,7 +51,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Skipf("could not start device %w", err)
}
time.Sleep(250 * time.Millisecond)
time.Sleep(dur)
if !d.IsRunning() {
t.Error("device isn't running, when it should be")
}
@ -59,7 +62,9 @@ func TestIsRunning(t *testing.T) {
if err != nil {
t.Error(err.Error())
}
time.Sleep(250 * time.Millisecond)
time.Sleep(dur)
if d.IsRunning() {
t.Error("device is running, when it should not be")
}