config_test.go 1.12 KB
Newer Older
ale's avatar
ale committed
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
54
package tabacco

import (
	"os"
	"testing"
)

func TestReadConfig(t *testing.T) {
	conf, err := ReadConfig("testdata/agent.yml")
	if err != nil {
		t.Fatal("ReadConfig()", err)
	}
	if len(conf.SourceSpecs) != 1 {
		t.Fatalf("no SourceSpecs in config: %+v", conf)
	}
	if len(conf.HandlerSpecs) != 1 {
		t.Fatalf("no HandlerSpecs in config: %+v", conf)
	}
}

func TestConfigManager(t *testing.T) {
	conf, err := ReadConfig("testdata/agent.yml")
	if err != nil {
		t.Fatal("ReadConfig()", err)
	}
	mgr, err := NewConfigManager(conf)
	if err != nil {
		t.Fatal("NewConfigManager()", err)
	}
	defer mgr.Close()

	// Test one of the accessor methods.
	if s := mgr.getSourceSpecs(); len(s) != 1 {
		t.Fatalf("getSourceSpecs() bad result: %+v", s)
	}

	// Test the Notify() mechanism by checking that it triggers
	// right away when setting up a new listener.
	<-mgr.Notify()
}

func TestRandomSeed(t *testing.T) {
	seedFile := ".test_seed"
	defer os.Remove(seedFile) // nolint

	seed := mustGetSeed(seedFile)
	if seed == 0 {
		t.Fatal("seed is zero")
	}
	seed2 := mustGetSeed(seedFile)
	if seed2 != seed {
		t.Fatal("failed to persist random seed")
	}
}