-
Notifications
You must be signed in to change notification settings - Fork 3
/
config_test.go
66 lines (56 loc) · 1.35 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
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"testing"
)
var MockConfigImport = `
import:
- https://raw.githubusercontent.com/niedbalski/repeat/master/example_metrics.yaml#md5sum=6c5b5d8fafd343d5cf452a7660ad9dd1
collections:
testing:
command: ps aux
process_list:
command: ps auxh
run-every: 2s
exit-codes: any
`
var MockConfigNoImport = `
collections:
testing:
command: ps aux
process_list:
command: ps auxh
run-every: 2s
exit-codes: any
`
var MockConfigNoImportNewCollections = `
collections:
felipestrolo:
command: ps aux
talks:
command: ps auxh
run-every: 2s
exit-codes: any
`
func TestLoadConfigMatchingCollections(t *testing.T) {
var config Config
_ = yaml.Unmarshal([]byte(MockConfigImport), &config)
err := LoadConfig(&config, func(url string) ([]byte, error) {
return []byte(MockConfigNoImport), nil
})
assert.Nil(t, err)
assert.NotNil(t, config)
assert.Len(t, config.Collections, 2)
}
func TestLoadConfigMultipleImports(t *testing.T) {
var config Config
_ = yaml.Unmarshal([]byte(MockConfigImport), &config)
LoadedImports = make(map[string]bool)
err := LoadConfig(&config, func(url string) ([]byte, error) {
return []byte(MockConfigNoImportNewCollections), nil
})
assert.Nil(t, err)
assert.NotNil(t, config)
assert.Len(t, config.Collections, 4)
}