2019-08-24 07:32:24 +03:00
|
|
|
/*
|
|
|
|
DESCRIPTION
|
|
|
|
config_test.go provides testing for configuration functionality found in config.go.
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package revid
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type dumbLogger struct{}
|
|
|
|
|
|
|
|
func (dl *dumbLogger) SetLevel(l int8) {}
|
|
|
|
func (dl *dumbLogger) Log(l int8, m string, p ...interface{}) {}
|
|
|
|
|
|
|
|
func TestValidate(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
in Config
|
|
|
|
check func(c Config) error
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
in: Config{Outputs: []uint8{HTTP}, Logger: &dumbLogger{}},
|
|
|
|
check: func(c Config) error {
|
|
|
|
if c.Bitrate != 0 {
|
|
|
|
return fmt.Errorf("did not get expected bitrate. Got: %v, Want: %v", c.Bitrate, 0)
|
|
|
|
}
|
|
|
|
if c.Quantization != defaultQuantization {
|
|
|
|
return fmt.Errorf("did not get expected quantization. Got: %v, Want: %v", c.Quantization, defaultQuantization)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-08-24 08:23:49 +03:00
|
|
|
in: Config{Outputs: []uint8{RTMP}, RTMPURL: "dummURL", Logger: &dumbLogger{}},
|
2019-08-24 07:32:24 +03:00
|
|
|
check: func(c Config) error {
|
|
|
|
if c.Bitrate != defaultBitrate {
|
|
|
|
return fmt.Errorf("did not get expected bitrate. Got: %v, Want: %v", c.Bitrate, defaultBitrate)
|
|
|
|
}
|
|
|
|
if c.Quantization != 0 {
|
|
|
|
return fmt.Errorf("did not get expected quantization. Got: %v, Want: %v", c.Quantization, 0)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: Config{Outputs: []uint8{HTTP}, Quantization: 50, Logger: &dumbLogger{}},
|
|
|
|
check: func(c Config) error { return nil },
|
|
|
|
err: errInvalidQuantization,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
in: Config{Outputs: []uint8{HTTP}, Quantization: 20, Logger: &dumbLogger{}},
|
|
|
|
check: func(c Config) error {
|
|
|
|
if c.Bitrate != 0 {
|
|
|
|
return fmt.Errorf("did not get expected bitrate. Got: %v, Want: %v", c.Bitrate, 0)
|
|
|
|
}
|
|
|
|
if c.Quantization != 20 {
|
|
|
|
return fmt.Errorf("did not get expected quantization. Got: %v, Want: %v", c.Quantization, 20)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
err := (&test.in).Validate()
|
|
|
|
if err != test.err {
|
|
|
|
t.Errorf("did not get expected error for test %d\nGot: %v\nWant: %v\n", i, err, test.err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = test.check(test.in)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("test %d failed with err: %v", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|