Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions handlers/container_metrics_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handlers_test

import (
"code.cloudfoundry.org/executor/containermetrics"
"errors"
"fmt"
"net/http"
Expand All @@ -24,12 +25,17 @@ var _ = Describe("ContainerMetrics", func() {
)

BeforeEach(func() {
one := uint64(1)
containerMetrics = &rep.ContainerMetricsCollection{
CellID: "some-cell-id",
LRPs: []rep.LRPMetric{
{
ProcessGUID: "some-process-guid",
InstanceGUID: "some-instance-guid",
CachedContainerMetrics: containermetrics.CachedContainerMetrics{
RxBytes: &one,
TxBytes: &one,
},
},
},
Tasks: []rep.TaskMetric{
Expand All @@ -49,22 +55,33 @@ var _ = Describe("ContainerMetrics", func() {
It("has the right field names", func() {
status, body := Request(rep.ContainerMetricsRoute, nil, nil)
Expect(status).To(Equal(http.StatusOK))
Expect(body).To(ContainSubstring(`process_guid`))
Expect(body).To(ContainSubstring(`instance_guid`))
Expect(body).To(ContainSubstring(`index`))
Expect(body).To(ContainSubstring(`metric_guid`))
Expect(body).To(ContainSubstring(`cpu_usage_fraction`))
Expect(body).To(ContainSubstring(`disk_usage_bytes`))
Expect(body).To(ContainSubstring(`disk_quota_bytes`))
Expect(body).To(ContainSubstring(`memory_usage_bytes`))
Expect(body).To(ContainSubstring(`memory_quota_bytes`))
Expect(body).To(ContainSubstring(`task_guid`))
Expect(body).To(ContainSubstring(`metric_guid`))
Expect(body).To(ContainSubstring(`cpu_usage_fraction`))
Expect(body).To(ContainSubstring(`disk_usage_bytes`))
Expect(body).To(ContainSubstring(`disk_quota_bytes`))
Expect(body).To(ContainSubstring(`memory_usage_bytes`))
Expect(body).To(ContainSubstring(`memory_quota_bytes`))

// part of the response up to "tasks"
lrps := strings.Split(string(body), "tasks")[0]
// part of the response after "tasks"
tasks := strings.Split(string(body), "tasks")[1]
Comment on lines +59 to +62
Copy link
Contributor Author

@geigerj0 geigerj0 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated cleanup: fixed the tests to do checks related to lrps / tasks part of the response


Expect(lrps).To(ContainSubstring(`process_guid`))
Expect(lrps).To(ContainSubstring(`instance_guid`))
Expect(lrps).To(ContainSubstring(`index`))
Expect(lrps).To(ContainSubstring(`metric_guid`))
Expect(lrps).To(ContainSubstring(`cpu_usage_fraction`))
Expect(lrps).To(ContainSubstring(`disk_usage_bytes`))
Expect(lrps).To(ContainSubstring(`disk_quota_bytes`))
Expect(lrps).To(ContainSubstring(`memory_usage_bytes`))
Expect(lrps).To(ContainSubstring(`memory_quota_bytes`))
Expect(lrps).To(ContainSubstring(`rx_bytes`))
Expect(lrps).To(ContainSubstring(`tx_bytes`))

Expect(tasks).To(ContainSubstring(`task_guid`))
Expect(tasks).To(ContainSubstring(`metric_guid`))
Expect(tasks).To(ContainSubstring(`cpu_usage_fraction`))
Expect(tasks).To(ContainSubstring(`disk_usage_bytes`))
Expect(tasks).To(ContainSubstring(`disk_quota_bytes`))
Expect(tasks).To(ContainSubstring(`memory_usage_bytes`))
Expect(tasks).To(ContainSubstring(`memory_quota_bytes`))
Expect(tasks).ToNot(ContainSubstring(`rx_bytes`))
Expect(tasks).ToNot(ContainSubstring(`tx_bytes`))
})

It("it returns whatever the container_metrics call returns", func() {
Expand Down