-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
53 lines (48 loc) · 1.37 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"io/ioutil"
"log"
"reflect"
"testing"
)
func init() {
log.SetOutput(ioutil.Discard)
}
func TestConfigLoad(t *testing.T) {
conf := loadConfig("./example-config.toml")
if conf.ScriptPath != "${HOME}/bin/udev.d" {
t.Error("Bad ScriptPath value: ", conf.ScriptPath)
}
if len(conf.Rules) != 3 {
t.Error("Wrong number of rules: ", len(conf.Rules))
}
if conf.Rules[1].PropName != "ID_MODEL" {
t.Error("Bad Rules field, got: ", conf.Rules[1].PropName,
"want: HID_NAME")
}
if !reflect.DeepEqual(conf.Rules[1].Args, []string{"set-default-sink", "Audioengine_D1"}) {
t.Error("Bad Args field, got: ", conf.Rules[1].Args,
"want: [set-default-sink, Audioengine_D1]")
}
}
func TestOverrides(t *testing.T) {
conf := &Config{subsystems: []string{"foo", "bar"}}
conf.overrideSubsystems([]string{})
if conf.subsystems[0] != "foo" {
t.Error("conf.subsystems replaced when it shouldn't have been.")
}
conf.overrideSubsystems([]string{"zed"})
if conf.subsystems[0] != "zed" {
t.Error("conf.subsystems not replaced when it should have been.")
}
if len(conf.subsystems) != 1 {
t.Error("conf.subsystems too long", len(conf.subsystems))
}
}
func TestAllSubsystems(t *testing.T) {
conf := &Config{subsystems: []string{"foo", "bar"}}
conf.overrideSubsystems([]string{"all"})
if len(conf.subsystems) != 0 {
t.Error("conf.subsystems 'all' didn't work")
}
}