-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscovery_test.go
More file actions
126 lines (98 loc) · 3.95 KB
/
discovery_test.go
File metadata and controls
126 lines (98 loc) · 3.95 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
const fixturesDir = "fixtures/pods"
func Test_NewDirListDiscoverer(t *testing.T) {
Convey("NewDirListDiscoverer() properly configures a discoverer", t, func() {
disco := NewDirListDiscoverer(fixturesDir, "dev")
So(disco.Dir, ShouldEqual, fixturesDir)
})
}
func Test_Discover(t *testing.T) {
Convey("Discover()", t, func() {
disco := NewDirListDiscoverer(fixturesDir, "dev")
Convey("finds all the pods, but not ourselves", func() {
capture := LogCapture(func() {
discovered, err := disco.Discover()
So(err, ShouldBeNil)
So(len(discovered), ShouldEqual, 7)
})
So(capture, ShouldNotContainSubstring, "Error")
So(capture, ShouldNotContainSubstring, "logtailer")
})
Convey("fills out the details properly for each", func() {
capture := LogCapture(func() {
discovered, err := disco.Discover()
So(err, ShouldBeNil)
So(discovered[1].Name, ShouldEqual, "default_chopper-f5b66c6bf-cgslk_9df92617-0407-470e-8182-a506aa7e0499")
So(discovered[1].Namespace, ShouldEqual, "default")
So(discovered[1].ServiceName, ShouldEqual, "chopper")
So(discovered[1].Environment, ShouldEqual, "dev")
So(discovered[2].Name, ShouldEqual, "default_kmtest_abe513f2-8a73-46f6-bd98-ec94e3de4012")
So(discovered[2].Namespace, ShouldEqual, "default")
So(discovered[2].ServiceName, ShouldEqual, "kmtest")
So(discovered[2].Environment, ShouldEqual, "dev")
So(discovered[3].Name, ShouldEqual, "default_pipeline-comparator-749f97cb4b-w8w4r_e5f10cd8-fb8a-4ade-b402-9b33f34f017f")
So(discovered[3].Namespace, ShouldEqual, "default")
So(discovered[3].ServiceName, ShouldEqual, "pipeline-comparator")
So(discovered[3].Environment, ShouldEqual, "dev")
})
So(capture, ShouldNotContainSubstring, "Error")
})
Convey("errors when it can't open the dir", func() {
disco := NewDirListDiscoverer("path-does-not-exist", "dev")
discovered, err := disco.Discover()
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "discovery failed")
So(discovered, ShouldBeNil)
})
})
}
func Test_LogFiles(t *testing.T) {
Convey("LogFiles()", t, func() {
disco := NewDirListDiscoverer(fixturesDir, "dev")
Convey("finds all the files", func() {
discovered, err := disco.LogFiles("default_pipeline-comparator-749f97cb4b-w8w4r_e5f10cd8-fb8a-4ade-b402-9b33f34f017f")
So(err, ShouldBeNil)
So(len(discovered), ShouldEqual, 3)
})
Convey("errors when the pod doesn't exist", func() {
discovered, err := disco.LogFiles("doesn't exist")
So(err, ShouldNotBeNil)
So(discovered, ShouldBeNil)
})
})
}
func Test_namesFor(t *testing.T) {
Convey("namesFor()", t, func() {
disco := NewDirListDiscoverer(fixturesDir, "dev")
Convey("handles names with dashes in them", func() {
ns, serviceName, err := disco.namesFor("default_pipeline-comparator-749f97cb4b-w8w4r_e5f10cd8-fb8a-4ade-b402-9b33f34f017f")
So(err, ShouldBeNil)
So(ns, ShouldEqual, "default")
So(serviceName, ShouldEqual, "pipeline-comparator")
})
Convey("handles names without dashes in them", func() {
ns, serviceName, err := disco.namesFor("default_chopper-f5b66c6bf-cgslk_9df92617-0407-470e-8182-a506aa7e0499")
So(err, ShouldBeNil)
So(ns, ShouldEqual, "default")
So(serviceName, ShouldEqual, "chopper")
})
Convey("errors when it gets some garbage with too few fields", func() {
ns, serviceName, err := disco.namesFor("default_chopper-f5b66c6bf-cgslk_")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "failed to parse")
So(ns, ShouldEqual, "")
So(serviceName, ShouldEqual, "")
})
Convey("errors when it gets some malformed garbage", func() {
ns, serviceName, err := disco.namesFor("default-chopper-f5b66c6bf-cgslk_9df92617-0407-470e-8182-a506aa7e0499")
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "failed to parse")
So(ns, ShouldEqual, "")
So(serviceName, ShouldEqual, "")
})
})
}