-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmetrics_test.go
65 lines (54 loc) · 1.98 KB
/
metrics_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
package throttle_test
import (
"errors"
"code.cloudfoundry.org/guardian/gardener"
"code.cloudfoundry.org/guardian/throttle"
"code.cloudfoundry.org/guardian/throttle/throttlefakes"
"code.cloudfoundry.org/lager/v3/lagertest"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("ContainerMetricsSource", func() {
var (
metricsSource throttle.MetricsSource
containerManager *throttlefakes.FakeContainerManager
logger *lagertest.TestLogger
metrics map[string]gardener.ActualContainerMetrics
collectMetricsErr error
)
BeforeEach(func() {
logger = lagertest.NewTestLogger("container-metrics-test")
containerManager = new(throttlefakes.FakeContainerManager)
containerManager.HandlesReturns([]string{"foo", "bar"}, nil)
containerManager.MetricsReturnsOnCall(0, containerMetric(1, 2), nil)
containerManager.MetricsReturnsOnCall(1, containerMetric(3, 4), nil)
metricsSource = throttle.NewContainerMetricsSource(containerManager)
})
JustBeforeEach(func() {
metrics, collectMetricsErr = metricsSource.CollectMetrics(logger)
})
It("collects metrics", func() {
Expect(collectMetricsErr).ToNot(HaveOccurred())
Expect(metrics).To(HaveLen(2))
Expect(metrics).To(HaveKeyWithValue("foo", containerMetric(1, 2)))
Expect(metrics).To(HaveKeyWithValue("bar", containerMetric(3, 4)))
})
When("listing container handles fails", func() {
BeforeEach(func() {
containerManager.HandlesReturns(nil, errors.New("list-containers-err"))
})
It("returns the error", func() {
Expect(collectMetricsErr).To(MatchError("list-containers-err"))
})
})
When("getting metrics for a handle fails", func() {
BeforeEach(func() {
containerManager.MetricsReturnsOnCall(0, gardener.ActualContainerMetrics{}, errors.New("metrics-err"))
})
It("continues without failing", func() {
Expect(collectMetricsErr).NotTo(HaveOccurred())
Expect(metrics).To(HaveLen(1))
Expect(metrics).To(HaveKeyWithValue("bar", containerMetric(3, 4)))
})
})
})