-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
79 lines (71 loc) · 3.29 KB
/
main_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
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
const NodeSpecFile = "test_data/nodes.yml"
const BrokenNodeSpecFile = "__BROKEN__nodes.yml__"
const ComponentsBase = "test_data/%s"
const BrokenComponentsBase = "__BROKEN__components_base__"
func TestStrictModeUnknownHost(t *testing.T) {
assert.Panics(t, func() {
classification := Classification{}
_ = classify(&classification, "unknown", NodeSpecFile, ComponentsBase, true)
}, "Should panic on unknown modes in strict mode")
}
func TestStrictModeUnknownComponent(t *testing.T) {
assert.Panics(t, func() {
classification := Classification{}
_ = classify(&classification, "broken-node", NodeSpecFile, ComponentsBase, true)
}, "Should panic on unknown component in strict mode")
}
func TestPrefixWithoutNodeSpec(t *testing.T) {
classification := Classification{}
err := classify(&classification, "unknown", BrokenNodeSpecFile, BrokenComponentsBase, false)
assert.NotNil(t, err, "Should return an error if no nodes.yml was found")
}
func TestKnownNodeClassification(t *testing.T) {
expectedClassification := Classification{
Classes: ClassTable{"apt": ClassTableEntry{"repos": map[interface{}]interface{}{
"backports": map[interface{}]interface{}{"host": "ftp.de.debian.org"},
"main": map[interface{}]interface{}{"host": "ftp.de.debian.org"},
"security": map[interface{}]interface{}{"host": "ftp.de.debian.org"},
"updates": map[interface{}]interface{}{"host": "ftp.de.debian.org"}},
}},
Data: DataTable{"bla::bla::blub": map[interface{}]interface{}{"value": "and stuff"}},
Parameters: DataTable{"such": "parameter"},
Environment: "production",
}
classification := Classification{}
err := classify(&classification, "test-node", NodeSpecFile, ComponentsBase, false)
assert.Nil(t, err, "Should not return an error for successful classifications")
assert.Equal(t, expectedClassification, classification, "Should classify correctly")
}
func TestUnknownNodeFallbackClassification(t *testing.T) {
expectedClassification := Classification{
Classes: ClassTable{"apt": ClassTableEntry{"repos": map[interface{}]interface{}{
"main": map[interface{}]interface{}{"host": "ftp.de.debian.org"},
"security": map[interface{}]interface{}{"host": "ftp.de.debian.org"},
"updates": map[interface{}]interface{}{"host": "ftp.de.debian.org"}},
}},
Data: DataTable{"bla::bla::blub": map[interface{}]interface{}{"value": "and stuff"}},
Parameters: DataTable{},
Environment: "production",
}
classification := Classification{}
err := classify(&classification, "__unknown_node__", NodeSpecFile, ComponentsBase, false)
assert.Nil(t, err, "No error on missing node in non-strict mode")
assert.Equal(t, expectedClassification, classification, "Should fallback correctly")
}
func TestResolutionOrder(t *testing.T) {
expectedClassification := Classification{
Classes: ClassTable{"a": ClassTableEntry{"b": 1}},
Data: DataTable{},
Parameters: DataTable{},
Environment: "production",
}
classification := Classification{}
err := classify(&classification, "prio-node", NodeSpecFile, ComponentsBase, true)
assert.Nil(t, err, "Should not return an error.")
assert.Equal(t, expectedClassification, classification, "Should traverse the implications in post-order to prioritize values higher up the tree.")
}