Skip to content

Commit

Permalink
Remove dot import from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminguttmann-avtq committed Oct 26, 2023
1 parent 53c84bf commit c21194a
Show file tree
Hide file tree
Showing 19 changed files with 489 additions and 489 deletions.
8 changes: 4 additions & 4 deletions collectors/collectors_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package collectors_test
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

func TestCollectors(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Collectors Suite")
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Collectors Suite")
}
68 changes: 34 additions & 34 deletions collectors/raw_metrics_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import (
"github.com/bosh-prometheus/firehose_exporter/metricmaker"
"github.com/bosh-prometheus/firehose_exporter/metrics"
"github.com/bosh-prometheus/firehose_exporter/testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"

"github.com/bosh-prometheus/firehose_exporter/collectors"
)

var _ = Describe("RawMetricsCollector", func() {
var _ = ginkgo.Describe("RawMetricsCollector", func() {
var pointBuffer chan []*metrics.RawMetric
var collector *collectors.RawMetricsCollector
BeforeEach(func() {
ginkgo.BeforeEach(func() {
pointBuffer = make(chan []*metrics.RawMetric)
collector = collectors.NewRawMetricsCollector(pointBuffer, 10*time.Minute)
})

AfterEach(func() {
ginkgo.AfterEach(func() {
close(pointBuffer)
})

Context("Collect", func() {
It("should save in metric store collected points", func() {
ginkgo.Context("Collect", func() {
ginkgo.It("should save in metric store collected points", func() {
go collector.Collect()
pointBuffer <- []*metrics.RawMetric{
metricmaker.NewRawMetricCounter("my_metric", map[string]string{
Expand All @@ -55,11 +55,11 @@ var _ = Describe("RawMetricsCollector", func() {

ms := collector.MetricStore()

Expect(ms).To(HaveKey("my_metric"))
Expect(ms).To(HaveKey("my_second_metric"))
Expect(ms["my_second_metric"]).To(HaveLen(1))
Expect(ms["my_metric"]).To(HaveLen(2))
Expect(ms["my_metric"]).To(testing.ContainPoints([]*metrics.RawMetric{
gomega.Expect(ms).To(gomega.HaveKey("my_metric"))
gomega.Expect(ms).To(gomega.HaveKey("my_second_metric"))
gomega.Expect(ms["my_second_metric"]).To(gomega.HaveLen(1))
gomega.Expect(ms["my_metric"]).To(gomega.HaveLen(2))
gomega.Expect(ms["my_metric"]).To(testing.ContainPoints([]*metrics.RawMetric{
metricmaker.NewRawMetricCounter("my_metric", map[string]string{
"origin": "my-origin",
"variadic": "2",
Expand All @@ -72,8 +72,8 @@ var _ = Describe("RawMetricsCollector", func() {

})

Context("CleanPeriodic", func() {
It("should clean swept metrics", func() {
ginkgo.Context("CleanPeriodic", func() {
ginkgo.It("should clean swept metrics", func() {
collector.SetCleanPeriodicDuration(70 * time.Millisecond)
go collector.Collect()
go collector.CleanPeriodic()
Expand All @@ -86,19 +86,19 @@ var _ = Describe("RawMetricsCollector", func() {
time.Sleep(50 * time.Millisecond)
m.SetSweep(true)
ms := collector.MetricStore()
Expect(ms).To(HaveKey("my_metric"))
Expect(ms["my_metric"]).To(HaveLen(1))
Expect(ms["my_metric"][0].IsSwept()).To(BeTrue())
gomega.Expect(ms).To(gomega.HaveKey("my_metric"))
gomega.Expect(ms["my_metric"]).To(gomega.HaveLen(1))
gomega.Expect(ms["my_metric"][0].IsSwept()).To(gomega.BeTrue())

time.Sleep(50 * time.Millisecond)
ms = collector.MetricStore()
Expect(ms).To(HaveKey("my_metric"))
Expect(ms["my_metric"]).To(HaveLen(0))
gomega.Expect(ms).To(gomega.HaveKey("my_metric"))
gomega.Expect(ms["my_metric"]).To(gomega.HaveLen(0))
})
})

Context("RenderExpFmt", func() {
BeforeEach(func() {
ginkgo.Context("RenderExpFmt", func() {
ginkgo.BeforeEach(func() {
go collector.Collect()
pointBuffer <- []*metrics.RawMetric{
metricmaker.NewRawMetricCounter("my_metric", map[string]string{
Expand All @@ -116,37 +116,37 @@ var _ = Describe("RawMetricsCollector", func() {
}
time.Sleep(50 * time.Millisecond)
})
It("should show metric in expfmt in plain text from registered internal metrics", func() {
ginkgo.It("should show metric in expfmt in plain text from registered internal metrics", func() {
respRec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
collector.RenderExpFmt(respRec, req)

content := respRec.Body.String()

Expect(content).To(ContainSubstring(`go_gc_duration_seconds`))
gomega.Expect(content).To(gomega.ContainSubstring(`go_gc_duration_seconds`))
})
When("no gzip is asked", func() {
It("should show metric in expfmt in plain text", func() {
ginkgo.When("no gzip is asked", func() {
ginkgo.It("should show metric in expfmt in plain text", func() {
respRec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
collector.RenderExpFmt(respRec, req)

content := respRec.Body.String()

Expect(content).To(ContainSubstring(`my_metric{origin="my-origin",variadic="1"} 1`))
Expect(content).To(ContainSubstring(`my_metric{origin="my-origin",variadic="2"} 1`))
Expect(content).To(ContainSubstring(`my_second_metric{origin="my-origin",variadic="1"} 1`))
gomega.Expect(content).To(gomega.ContainSubstring(`my_metric{origin="my-origin",variadic="1"} 1`))
gomega.Expect(content).To(gomega.ContainSubstring(`my_metric{origin="my-origin",variadic="2"} 1`))
gomega.Expect(content).To(gomega.ContainSubstring(`my_second_metric{origin="my-origin",variadic="1"} 1`))
})
})
When("with gzip is asked", func() {
It("should show metric in expfmt in gzip", func() {
ginkgo.When("with gzip is asked", func() {
ginkgo.It("should show metric in expfmt in gzip", func() {
respRec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req.Header.Set("Accept-Encoding", "gzip")
collector.RenderExpFmt(respRec, req)

gzipReader, err := gzip.NewReader(respRec.Body)
Expect(err).ToNot(HaveOccurred())
gomega.Expect(err).ToNot(gomega.HaveOccurred())
defer gzipReader.Close()

var resB bytes.Buffer
Expand All @@ -157,9 +157,9 @@ var _ = Describe("RawMetricsCollector", func() {

content := resB.String()

Expect(content).To(ContainSubstring(`my_metric{origin="my-origin",variadic="1"} 1`))
Expect(content).To(ContainSubstring(`my_metric{origin="my-origin",variadic="2"} 1`))
Expect(content).To(ContainSubstring(`my_second_metric{origin="my-origin",variadic="1"} 1`))
gomega.Expect(content).To(gomega.ContainSubstring(`my_metric{origin="my-origin",variadic="1"} 1`))
gomega.Expect(content).To(gomega.ContainSubstring(`my_metric{origin="my-origin",variadic="2"} 1`))
gomega.Expect(content).To(gomega.ContainSubstring(`my_second_metric{origin="my-origin",variadic="1"} 1`))
})
})
})
Expand Down
36 changes: 18 additions & 18 deletions metricmaker/compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@ package metricmaker_test

import (
"github.com/bosh-prometheus/firehose_exporter/metricmaker"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

var _ = Describe("Compat", func() {
BeforeEach(func() {
var _ = ginkgo.Describe("Compat", func() {
ginkgo.BeforeEach(func() {
metricmaker.SetMetricConverters(make([]metricmaker.MetricConverter, 0))
})
Describe("RetroCompatMetricNames", func() {
Context("when have a container metric", func() {
It("should rename metric name with old name", func() {
ginkgo.Describe("RetroCompatMetricNames", func() {
ginkgo.Context("when have a container metric", func() {
ginkgo.It("should rename metric name with old name", func() {
m := metricmaker.NewRawMetricGauge("cpu", make(map[string]string), 0)
metricmaker.RetroCompatMetricNames(m)
Expect(m.MetricName()).To(Equal("container_metric_cpu_percentage"))
gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_cpu_percentage"))

m = metricmaker.NewRawMetricGauge("memory", make(map[string]string), 0)
metricmaker.RetroCompatMetricNames(m)
Expect(m.MetricName()).To(Equal("container_metric_memory_bytes"))
gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_memory_bytes"))

m = metricmaker.NewRawMetricGauge("disk", make(map[string]string), 0)
metricmaker.RetroCompatMetricNames(m)
Expect(m.MetricName()).To(Equal("container_metric_disk_bytes"))
gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_disk_bytes"))

m = metricmaker.NewRawMetricGauge("memory_quota", make(map[string]string), 0)
metricmaker.RetroCompatMetricNames(m)
Expect(m.MetricName()).To(Equal("container_metric_memory_bytes_quota"))
gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_memory_bytes_quota"))

m = metricmaker.NewRawMetricGauge("disk_quota", make(map[string]string), 0)
metricmaker.RetroCompatMetricNames(m)
Expect(m.MetricName()).To(Equal("container_metric_disk_bytes_quota"))
gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_disk_bytes_quota"))
})
})
Context("when have a counter metric which is not a container metric", func() {
It("should prefix with counter_event_ add origin and suffix with total", func() {
ginkgo.Context("when have a counter metric which is not a container metric", func() {
ginkgo.It("should prefix with counter_event_ add origin and suffix with total", func() {
m := metricmaker.NewRawMetricCounter("my_metric", make(map[string]string), 0)
m.SetOrigin("origin")
metricmaker.RetroCompatMetricNames(m)
Expect(m.MetricName()).To(Equal("counter_event_origin_my_metric_total"))
gomega.Expect(m.MetricName()).To(gomega.Equal("counter_event_origin_my_metric_total"))
})
})
Context("when have a gauge metric which is not a container metric", func() {
It("should prefix with value_metric_ add origin", func() {
ginkgo.Context("when have a gauge metric which is not a container metric", func() {
ginkgo.It("should prefix with value_metric_ add origin", func() {
m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0)
m.SetOrigin("origin")
metricmaker.RetroCompatMetricNames(m)
Expect(m.MetricName()).To(Equal("value_metric_origin_my_metric"))
gomega.Expect(m.MetricName()).To(gomega.Equal("value_metric_origin_my_metric"))
})
})
})
Expand Down
78 changes: 39 additions & 39 deletions metricmaker/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,58 @@ package metricmaker_test
import (
"github.com/bosh-prometheus/firehose_exporter/metricmaker"
"github.com/bosh-prometheus/firehose_exporter/transform"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

var _ = Describe("Converters", func() {
BeforeEach(func() {
var _ = ginkgo.Describe("Converters", func() {
ginkgo.BeforeEach(func() {
metricmaker.SetMetricConverters(make([]metricmaker.MetricConverter, 0))
})

Describe("NormalizeName", func() {
It("should reformat name", func() {
ginkgo.Describe("NormalizeName", func() {
ginkgo.It("should reformat name", func() {
m := metricmaker.NewRawMetricGauge("FooBar", make(map[string]string), 0)
metricmaker.NormalizeName(m)
Expect(m.MetricName()).To(Equal("foo_bar"))
gomega.Expect(m.MetricName()).To(gomega.Equal("foo_bar"))

})
})

Describe("AddNamespace", func() {
It("should prefix with namespace given", func() {
ginkgo.Describe("AddNamespace", func() {
ginkgo.It("should prefix with namespace given", func() {
m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0)
metricmaker.AddNamespace("namespace")(m)
Expect(m.MetricName()).To(Equal("namespace_my_metric"))
gomega.Expect(m.MetricName()).To(gomega.Equal("namespace_my_metric"))
})
})

Describe("FindAndReplaceByName", func() {
It("should only replace name if found", func() {
ginkgo.Describe("FindAndReplaceByName", func() {
ginkgo.It("should only replace name if found", func() {
m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0)
metricmaker.FindAndReplaceByName("foo", "bar")(m)
Expect(m.MetricName()).To(Equal("my_metric"))
gomega.Expect(m.MetricName()).To(gomega.Equal("my_metric"))

m = metricmaker.NewRawMetricGauge("foo", make(map[string]string), 0)
metricmaker.FindAndReplaceByName("foo", "bar")(m)
Expect(m.MetricName()).To(Equal("bar"))
gomega.Expect(m.MetricName()).To(gomega.Equal("bar"))
})
})

Describe("InjectMapLabel", func() {
It("should inject label given", func() {
ginkgo.Describe("InjectMapLabel", func() {
ginkgo.It("should inject label given", func() {
m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0)
metricmaker.InjectMapLabel(map[string]string{
"foo": "bar",
})(m)
Expect(m.Metric().Label).To(HaveLen(1))
Expect(m.Metric().Label[0].GetName()).To(Equal("foo"))
Expect(m.Metric().Label[0].GetValue()).To(Equal("bar"))
gomega.Expect(m.Metric().Label).To(gomega.HaveLen(1))
gomega.Expect(m.Metric().Label[0].GetName()).To(gomega.Equal("foo"))
gomega.Expect(m.Metric().Label[0].GetValue()).To(gomega.Equal("bar"))
})
})

Describe("PresetLabels", func() {
It("should rewrite labels", func() {
ginkgo.Describe("PresetLabels", func() {
ginkgo.It("should rewrite labels", func() {
m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0)
m.Metric().Label = transform.LabelsMapToLabelPairs(map[string]string{
"deployment": "deployment",
Expand All @@ -63,18 +63,18 @@ var _ = Describe("Converters", func() {
"ip": "127.0.0.1",
})
metricmaker.PresetLabels(m)
Expect(m.Metric().Label).To(HaveLen(8))
gomega.Expect(m.Metric().Label).To(gomega.HaveLen(8))
labelsMap := transform.LabelPairsToLabelsMap(m.Metric().Label)

Expect(labelsMap).To(HaveKeyWithValue("bosh_deployment", "deployment"))
Expect(labelsMap).To(HaveKeyWithValue("bosh_job_name", "job"))
Expect(labelsMap).To(HaveKeyWithValue("bosh_job_id", "0"))
Expect(labelsMap).To(HaveKeyWithValue("bosh_job_ip", "127.0.0.1"))
gomega.Expect(labelsMap).To(gomega.HaveKeyWithValue("bosh_deployment", "deployment"))
gomega.Expect(labelsMap).To(gomega.HaveKeyWithValue("bosh_job_name", "job"))
gomega.Expect(labelsMap).To(gomega.HaveKeyWithValue("bosh_job_id", "0"))
gomega.Expect(labelsMap).To(gomega.HaveKeyWithValue("bosh_job_ip", "127.0.0.1"))
})
})

Describe("OrderAndSanitizeLabels", func() {
It("should order and sanitize labels", func() {
ginkgo.Describe("OrderAndSanitizeLabels", func() {
ginkgo.It("should order and sanitize labels", func() {
m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0)
m.Metric().Label = transform.LabelsMapToLabelPairs(map[string]string{
"job": "job",
Expand All @@ -87,28 +87,28 @@ var _ = Describe("Converters", func() {
metricmaker.OrderAndSanitizeLabels(m)

labels := m.Metric().Label
Expect(m.Metric().Label).To(HaveLen(5))
Expect(labels[0].GetName()).To(Equal("deployment"))
Expect(labels[1].GetName()).To(Equal("index"))
Expect(labels[2].GetName()).To(Equal("ip"))
Expect(labels[3].GetName()).To(Equal("job"))
Expect(labels[4].GetName()).To(Equal("label_dash"))
gomega.Expect(m.Metric().Label).To(gomega.HaveLen(5))
gomega.Expect(labels[0].GetName()).To(gomega.Equal("deployment"))
gomega.Expect(labels[1].GetName()).To(gomega.Equal("index"))
gomega.Expect(labels[2].GetName()).To(gomega.Equal("ip"))
gomega.Expect(labels[3].GetName()).To(gomega.Equal("job"))
gomega.Expect(labels[4].GetName()).To(gomega.Equal("label_dash"))
})
})

Describe("SuffixCounterWithTotal", func() {
It("should suffix only counter metrics without _total suffix with it", func() {
ginkgo.Describe("SuffixCounterWithTotal", func() {
ginkgo.It("should suffix only counter metrics without _total suffix with it", func() {
m := metricmaker.NewRawMetricCounter("my_metric", make(map[string]string), 0)
metricmaker.SuffixCounterWithTotal(m)
Expect(m.MetricName()).To(Equal("my_metric_total"))
gomega.Expect(m.MetricName()).To(gomega.Equal("my_metric_total"))

m = metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0)
metricmaker.SuffixCounterWithTotal(m)
Expect(m.MetricName()).To(Equal("my_metric"))
gomega.Expect(m.MetricName()).To(gomega.Equal("my_metric"))

m = metricmaker.NewRawMetricGauge("my_metric_total", make(map[string]string), 0)
metricmaker.SuffixCounterWithTotal(m)
Expect(m.MetricName()).To(Equal("my_metric_total"))
gomega.Expect(m.MetricName()).To(gomega.Equal("my_metric_total"))
})
})
})
8 changes: 4 additions & 4 deletions metricmaker/metricmaker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package metricmaker_test
import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

func TestMetricmaker(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Metricate Suite")
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Metricate Suite")
}
Loading

0 comments on commit c21194a

Please sign in to comment.