diff --git a/collectors/bosh_collector_test.go b/collectors/bosh_collector_test.go index 16fcc246..30faaaf6 100644 --- a/collectors/bosh_collector_test.go +++ b/collectors/bosh_collector_test.go @@ -4,8 +4,8 @@ import ( "errors" "os" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "github.com/cloudfoundry/bosh-cli/director" "github.com/cloudfoundry/bosh-cli/director/directorfakes" @@ -15,15 +15,15 @@ import ( "github.com/bosh-prometheus/bosh_exporter/deployments" "github.com/bosh-prometheus/bosh_exporter/filters" - . "github.com/bosh-prometheus/bosh_exporter/collectors" - . "github.com/bosh-prometheus/bosh_exporter/utils/matchers" + "github.com/bosh-prometheus/bosh_exporter/collectors" + "github.com/bosh-prometheus/bosh_exporter/utils/matchers" ) func init() { _ = log.Base().SetLevel("fatal") } -var _ = Describe("BoshCollector", func() { +var _ = ginkgo.Describe("BoshCollector", func() { var ( err error namespace string @@ -41,8 +41,8 @@ var _ = Describe("BoshCollector", func() { azsFilter *filters.AZsFilter processesFilter *filters.RegexpFilter cidrsFilter *filters.CidrFilter - metrics *BoshCollectorMetrics - boshCollector *BoshCollector + metrics *collectors.BoshCollectorMetrics + boshCollector *collectors.BoshCollector totalBoshScrapesMetric prometheus.Counter totalBoshScrapeErrorsMetric prometheus.Counter @@ -51,14 +51,14 @@ var _ = Describe("BoshCollector", func() { lastBoshScrapeDurationSecondsMetric prometheus.Gauge ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { namespace = testNamespace environment = testEnvironment boshName = testBoshName boshUUID = testBoshUUID - metrics = NewBoshCollectorMetrics(testNamespace, testEnvironment, testBoshName, testBoshUUID) + metrics = collectors.NewBoshCollectorMetrics(testNamespace, testEnvironment, testBoshName, testBoshUUID) tmpfile, err = os.CreateTemp("", "service_discovery_collector_test_") - Expect(err).ToNot(HaveOccurred()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) serviceDiscoveryFilename = tmpfile.Name() boshDeployments = []string{} @@ -66,12 +66,12 @@ var _ = Describe("BoshCollector", func() { deploymentsFilter = filters.NewDeploymentsFilter(boshDeployments, boshClient) deploymentsFetcher = deployments.NewFetcher(*deploymentsFilter) collectorsFilter, err = filters.NewCollectorsFilter([]string{}) - Expect(err).ToNot(HaveOccurred()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) azsFilter = filters.NewAZsFilter([]string{}) cidrsFilter, err = filters.NewCidrFilter([]string{}) - Expect(err).ToNot(HaveOccurred()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) processesFilter, err = filters.NewRegexpFilter([]string{}) - Expect(err).ToNot(HaveOccurred()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) totalBoshScrapesMetric = metrics.NewTotalBoshScrapesMetric() totalBoshScrapesMetric.Inc() @@ -82,13 +82,13 @@ var _ = Describe("BoshCollector", func() { lastBoshScrapeDurationSecondsMetric = metrics.NewLastBoshScrapeDurationSecondsMetric() }) - AfterEach(func() { + ginkgo.AfterEach(func() { err = os.Remove(serviceDiscoveryFilename) - Expect(err).ToNot(HaveOccurred()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) - JustBeforeEach(func() { - boshCollector = NewBoshCollector( + ginkgo.JustBeforeEach(func() { + boshCollector = collectors.NewBoshCollector( namespace, environment, boshName, @@ -102,79 +102,79 @@ var _ = Describe("BoshCollector", func() { ) }) - Describe("Describe", func() { + ginkgo.Describe("Describe", func() { var ( descriptions chan *prometheus.Desc ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { descriptions = make(chan *prometheus.Desc) }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { go boshCollector.Describe(descriptions) }) - It("returns a scrapes_total description", func() { - Eventually(descriptions).Should(Receive(Equal(totalBoshScrapesMetric.Desc()))) + ginkgo.It("returns a scrapes_total description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(totalBoshScrapesMetric.Desc()))) }) - It("returns a scrape_errors_total description", func() { - Eventually(descriptions).Should(Receive(Equal(totalBoshScrapeErrorsMetric.Desc()))) + ginkgo.It("returns a scrape_errors_total description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(totalBoshScrapeErrorsMetric.Desc()))) }) - It("returns a last_scrape_error description", func() { - Eventually(descriptions).Should(Receive(Equal(lastBoshScrapeErrorMetric.Desc()))) + ginkgo.It("returns a last_scrape_error description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(lastBoshScrapeErrorMetric.Desc()))) }) - It("returns a last_scrape_timestamp metric description", func() { - Eventually(descriptions).Should(Receive(Equal(lastBoshScrapeTimestampMetric.Desc()))) + ginkgo.It("returns a last_scrape_timestamp metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(lastBoshScrapeTimestampMetric.Desc()))) }) - It("returns a last_scrape_duration_seconds metric description", func() { - Eventually(descriptions).Should(Receive(Equal(lastBoshScrapeDurationSecondsMetric.Desc()))) + ginkgo.It("returns a last_scrape_duration_seconds metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(lastBoshScrapeDurationSecondsMetric.Desc()))) }) }) - Describe("Collect", func() { + ginkgo.Describe("Collect", func() { var ( metrics chan prometheus.Metric ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { metrics = make(chan prometheus.Metric) }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { go boshCollector.Collect(metrics) }) - It("returns a scrapes_total metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(totalBoshScrapesMetric))) + ginkgo.It("returns a scrapes_total metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(totalBoshScrapesMetric))) }) - It("returns a scrape_errors_total metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(totalBoshScrapeErrorsMetric))) + ginkgo.It("returns a scrape_errors_total metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(totalBoshScrapeErrorsMetric))) }) - It("returns a last_scrape_error metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(lastBoshScrapeErrorMetric))) + ginkgo.It("returns a last_scrape_error metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(lastBoshScrapeErrorMetric))) }) - Context("when it fails to get the deployment", func() { - BeforeEach(func() { + ginkgo.Context("when it fails to get the deployment", func() { + ginkgo.BeforeEach(func() { boshClient.DeploymentsReturns([]director.Deployment{}, errors.New("no deployments")) totalBoshScrapeErrorsMetric.Inc() lastBoshScrapeErrorMetric.Set(float64(1)) }) - It("returns a scrape_errors_total metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(totalBoshScrapeErrorsMetric))) + ginkgo.It("returns a scrape_errors_total metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(totalBoshScrapeErrorsMetric))) }) - It("returns a last_scrape_error metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(lastBoshScrapeErrorMetric))) + ginkgo.It("returns a last_scrape_error metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(lastBoshScrapeErrorMetric))) }) }) }) diff --git a/collectors/collectors_suite_test.go b/collectors/collectors_suite_test.go index cf3ab13f..7f023598 100644 --- a/collectors/collectors_suite_test.go +++ b/collectors/collectors_suite_test.go @@ -1,8 +1,8 @@ package collectors_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "testing" ) @@ -15,6 +15,6 @@ const ( ) func TestCollectors(t *testing.T) { - RegisterFailHandler(AbortSuite) - RunSpecs(t, "Collectors Suite") + gomega.RegisterFailHandler(ginkgo.AbortSuite) + ginkgo.RunSpecs(t, "Collectors Suite") } diff --git a/collectors/deployments_collector_test.go b/collectors/deployments_collector_test.go index f79f4146..c8283ad9 100644 --- a/collectors/deployments_collector_test.go +++ b/collectors/deployments_collector_test.go @@ -1,30 +1,30 @@ package collectors_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/log" "github.com/bosh-prometheus/bosh_exporter/deployments" - . "github.com/bosh-prometheus/bosh_exporter/collectors" - . "github.com/bosh-prometheus/bosh_exporter/utils/matchers" + "github.com/bosh-prometheus/bosh_exporter/collectors" + "github.com/bosh-prometheus/bosh_exporter/utils/matchers" ) func init() { _ = log.Base().SetLevel("fatal") } -var _ = Describe("DeploymentsCollector", func() { +var _ = ginkgo.Describe("DeploymentsCollector", func() { var ( namespace string environment string boshName string boshUUID string - metrics *DeploymentsCollectorMetrics - deploymentsCollector *DeploymentsCollector + metrics *collectors.DeploymentsCollectorMetrics + deploymentsCollector *collectors.DeploymentsCollector deploymentReleaseInfoMetric *prometheus.GaugeVec deploymentReleaseJobInfoMetric *prometheus.GaugeVec @@ -47,12 +47,12 @@ var _ = Describe("DeploymentsCollector", func() { vmTypeLarge = "fake-vm-type-large" ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { namespace = testNamespace environment = testEnvironment boshName = testBoshName boshUUID = testBoshUUID - metrics = NewDeploymentsCollectorMetrics(testNamespace, testEnvironment, testBoshName, testBoshUUID) + metrics = collectors.NewDeploymentsCollectorMetrics(testNamespace, testEnvironment, testBoshName, testBoshUUID) deploymentReleaseInfoMetric = metrics.NewDeploymentReleaseInfoMetric() deploymentReleaseInfoMetric.WithLabelValues( @@ -104,8 +104,8 @@ var _ = Describe("DeploymentsCollector", func() { lastDeploymentsScrapeDurationSecondsMetric = metrics.NewLastDeploymentsScrapeDurationSecondsMetric() }) - JustBeforeEach(func() { - deploymentsCollector = NewDeploymentsCollector( + ginkgo.JustBeforeEach(func() { + deploymentsCollector = collectors.NewDeploymentsCollector( namespace, environment, boshName, @@ -113,29 +113,29 @@ var _ = Describe("DeploymentsCollector", func() { ) }) - Describe("Describe", func() { + ginkgo.Describe("Describe", func() { var ( descriptions chan *prometheus.Desc ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { descriptions = make(chan *prometheus.Desc) }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { go deploymentsCollector.Describe(descriptions) }) - It("returns a deployment_release_info description", func() { - Eventually(descriptions).Should(Receive(Equal(deploymentReleaseInfoMetric.WithLabelValues( + ginkgo.It("returns a deployment_release_info description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(deploymentReleaseInfoMetric.WithLabelValues( deploymentName, releaseName, releaseVersion, ).Desc()))) }) - It("returns a deployment_release_job_info description", func() { - Eventually(descriptions).Should(Receive(Equal(deploymentReleaseJobInfoMetric.WithLabelValues( + ginkgo.It("returns a deployment_release_job_info description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(deploymentReleaseJobInfoMetric.WithLabelValues( deploymentName, releaseName, releaseVersion, @@ -143,8 +143,8 @@ var _ = Describe("DeploymentsCollector", func() { ).Desc()))) }) - It("returns a deployment_release_package_info description", func() { - Eventually(descriptions).Should(Receive(Equal(deploymentReleasePackageInfoMetric.WithLabelValues( + ginkgo.It("returns a deployment_release_package_info description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(deploymentReleasePackageInfoMetric.WithLabelValues( deploymentName, releaseName, releaseVersion, @@ -152,8 +152,8 @@ var _ = Describe("DeploymentsCollector", func() { ).Desc()))) }) - It("returns a deployment_stemcell_info metric description", func() { - Eventually(descriptions).Should(Receive(Equal(deploymentStemcellInfoMetric.WithLabelValues( + ginkgo.It("returns a deployment_stemcell_info metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(deploymentStemcellInfoMetric.WithLabelValues( deploymentName, stemcellName, stemcellVersion, @@ -161,23 +161,23 @@ var _ = Describe("DeploymentsCollector", func() { ).Desc()))) }) - It("returns a deployment_instances metric description", func() { - Eventually(descriptions).Should(Receive(Equal(deploymentInstancesMetric.WithLabelValues( + ginkgo.It("returns a deployment_instances metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(deploymentInstancesMetric.WithLabelValues( deploymentName, vmTypeSmall, ).Desc()))) }) - It("returns a last_deployments_scrape_timestamp metric description", func() { - Eventually(descriptions).Should(Receive(Equal(lastDeploymentsScrapeTimestampMetric.Desc()))) + ginkgo.It("returns a last_deployments_scrape_timestamp metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(lastDeploymentsScrapeTimestampMetric.Desc()))) }) - It("returns a last_deployments_scrape_duration_seconds metric description", func() { - Eventually(descriptions).Should(Receive(Equal(lastDeploymentsScrapeDurationSecondsMetric.Desc()))) + ginkgo.It("returns a last_deployments_scrape_duration_seconds metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(lastDeploymentsScrapeDurationSecondsMetric.Desc()))) }) }) - Describe("Collect", func() { + ginkgo.Describe("Collect", func() { var ( release = deployments.Release{ Name: releaseName, @@ -211,7 +211,7 @@ var _ = Describe("DeploymentsCollector", func() { errMetrics chan error ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { deploymentInfo = deployments.DeploymentInfo{ Name: deploymentName, Releases: releases, @@ -224,7 +224,7 @@ var _ = Describe("DeploymentsCollector", func() { errMetrics = make(chan error, 1) }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { go func() { if err := deploymentsCollector.Collect(deploymentsInfo, metrics); err != nil { errMetrics <- err @@ -232,127 +232,127 @@ var _ = Describe("DeploymentsCollector", func() { }() }) - It("returns a deployment_release_info metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(deploymentReleaseInfoMetric.WithLabelValues( + ginkgo.It("returns a deployment_release_info metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(deploymentReleaseInfoMetric.WithLabelValues( deploymentName, releaseName, releaseVersion, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - It("returns a deployment_release_job_info metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(deploymentReleaseJobInfoMetric.WithLabelValues( + ginkgo.It("returns a deployment_release_job_info metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(deploymentReleaseJobInfoMetric.WithLabelValues( deploymentName, releaseName, releaseVersion, releaseJobName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - It("returns a deployment_release_package_info metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(deploymentReleasePackageInfoMetric.WithLabelValues( + ginkgo.It("returns a deployment_release_package_info metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(deploymentReleasePackageInfoMetric.WithLabelValues( deploymentName, releaseName, releaseVersion, releasePackageName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - It("returns a deployment_stemcell_info metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(deploymentStemcellInfoMetric.WithLabelValues( + ginkgo.It("returns a deployment_stemcell_info metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(deploymentStemcellInfoMetric.WithLabelValues( deploymentName, stemcellName, stemcellVersion, stemcellOSName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - It("returns a deployment_instances for small vmType instance", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(deploymentInstancesMetric.WithLabelValues( + ginkgo.It("returns a deployment_instances for small vmType instance", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(deploymentInstancesMetric.WithLabelValues( deploymentName, vmTypeSmall, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - It("returns a deployment_instances for medium vmType instance", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(deploymentInstancesMetric.WithLabelValues( + ginkgo.It("returns a deployment_instances for medium vmType instance", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(deploymentInstancesMetric.WithLabelValues( deploymentName, vmTypeMedium, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - It("returns a deployment_instances for large vmType instance", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(deploymentInstancesMetric.WithLabelValues( + ginkgo.It("returns a deployment_instances for large vmType instance", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(deploymentInstancesMetric.WithLabelValues( deploymentName, vmTypeLarge, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there are no deployments", func() { - BeforeEach(func() { + ginkgo.Context("when there are no deployments", func() { + ginkgo.BeforeEach(func() { deploymentsInfo = []deployments.DeploymentInfo{} }) - It("returns only a last_deployments_scrape_timestamp & last_deployments_scrape_duration_seconds metric", func() { - Eventually(metrics).Should(Receive()) - Eventually(metrics).Should(Receive()) - Consistently(metrics).ShouldNot(Receive()) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns only a last_deployments_scrape_timestamp & last_deployments_scrape_duration_seconds metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Consistently(metrics).ShouldNot(gomega.Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - Context("when there are no releases", func() { - BeforeEach(func() { + ginkgo.Context("when there are no releases", func() { + ginkgo.BeforeEach(func() { deploymentInfo.Releases = []deployments.Release{} deploymentsInfo = []deployments.DeploymentInfo{deploymentInfo} }) - It("should not return a deployment_release_info metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(deploymentReleaseInfoMetric.WithLabelValues( + ginkgo.It("should not return a deployment_release_info metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(deploymentReleaseInfoMetric.WithLabelValues( deploymentName, releaseName, releaseVersion, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - Context("when there are no stemcells", func() { - BeforeEach(func() { + ginkgo.Context("when there are no stemcells", func() { + ginkgo.BeforeEach(func() { deploymentInfo.Stemcells = []deployments.Stemcell{} deploymentsInfo = []deployments.DeploymentInfo{deploymentInfo} }) - It("should not return a deployment_stemcell_info metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(deploymentStemcellInfoMetric.WithLabelValues( + ginkgo.It("should not return a deployment_stemcell_info metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(deploymentStemcellInfoMetric.WithLabelValues( deploymentName, stemcellName, stemcellVersion, stemcellOSName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - Context("when there are no instances", func() { - BeforeEach(func() { + ginkgo.Context("when there are no instances", func() { + ginkgo.BeforeEach(func() { deploymentInfo.Instances = []deployments.Instance{} deploymentsInfo = []deployments.DeploymentInfo{deploymentInfo} }) - It("should not return a deployment_instances metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(deploymentInstancesMetric.WithLabelValues( + ginkgo.It("should not return a deployment_instances metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(deploymentInstancesMetric.WithLabelValues( deploymentName, vmTypeSmall, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) }) diff --git a/collectors/jobs_collector_test.go b/collectors/jobs_collector_test.go index f1da4ada..3b88c898 100644 --- a/collectors/jobs_collector_test.go +++ b/collectors/jobs_collector_test.go @@ -3,8 +3,8 @@ package collectors_test import ( "strconv" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/log" @@ -12,8 +12,8 @@ import ( "github.com/bosh-prometheus/bosh_exporter/deployments" "github.com/bosh-prometheus/bosh_exporter/filters" - . "github.com/bosh-prometheus/bosh_exporter/collectors" - . "github.com/bosh-prometheus/bosh_exporter/utils/matchers" + "github.com/bosh-prometheus/bosh_exporter/collectors" + "github.com/bosh-prometheus/bosh_exporter/utils/matchers" ) func init() { @@ -35,7 +35,7 @@ func (b *BaseLabelValues) AddLabelValues(gaugeVec *prometheus.GaugeVec, lvs ...s return gaugeVec.WithLabelValues(values...) } -var _ = Describe("JobsCollector", func() { +var _ = ginkgo.Describe("JobsCollector", func() { var ( err error namespace string @@ -44,8 +44,8 @@ var _ = Describe("JobsCollector", func() { boshUUID string azsFilter *filters.AZsFilter cidrsFilter *filters.CidrFilter - metrics *JobsCollectorMetrics - jobsCollector *JobsCollector + metrics *collectors.JobsCollectorMetrics + jobsCollector *collectors.JobsCollector jobHealthyMetric *prometheus.GaugeVec jobLoadAvg01Metric *prometheus.GaugeVec @@ -108,15 +108,15 @@ var _ = Describe("JobsCollector", func() { jobProcessReleaseVersion = "fake-process-release-version" ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { namespace = testNamespace environment = testEnvironment boshName = testBoshName boshUUID = testBoshUUID - metrics = NewJobsCollectorMetrics(testNamespace, testEnvironment, testBoshName, testBoshUUID) + metrics = collectors.NewJobsCollectorMetrics(testNamespace, testEnvironment, testBoshName, testBoshUUID) azsFilter = filters.NewAZsFilter([]string{}) cidrsFilter, err = filters.NewCidrFilter([]string{"0.0.0.0/0"}) - Expect(err).ToNot(HaveOccurred()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) jobHealthyMetric = metrics.NewJobHealthyMetric() baseLabelValues.AddLabelValues(jobHealthyMetric).Set(float64(1)) @@ -191,125 +191,125 @@ var _ = Describe("JobsCollector", func() { lastJobsScrapeDurationSecondsMetric = metrics.NewLastJobsScrapeDurationSecondsMetric() }) - JustBeforeEach(func() { - jobsCollector = NewJobsCollector(namespace, environment, boshName, boshUUID, azsFilter, cidrsFilter) + ginkgo.JustBeforeEach(func() { + jobsCollector = collectors.NewJobsCollector(namespace, environment, boshName, boshUUID, azsFilter, cidrsFilter) }) - Describe("Describe", func() { + ginkgo.Describe("ginkgo.Describe", func() { var ( descriptions chan *prometheus.Desc ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { descriptions = make(chan *prometheus.Desc) }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { go jobsCollector.Describe(descriptions) }) - It("returns a job_healthy metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobHealthyMetric).Desc()))) + ginkgo.It("returns a job_healthy metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobHealthyMetric).Desc()))) }) - It("returns a job_load_avg01 metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobLoadAvg01Metric).Desc()))) + ginkgo.It("returns a job_load_avg01 metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobLoadAvg01Metric).Desc()))) }) - It("returns a job_load_avg05 metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobLoadAvg05Metric).Desc()))) + ginkgo.It("returns a job_load_avg05 metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobLoadAvg05Metric).Desc()))) }) - It("returns a job_load_avg15 metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobLoadAvg15Metric).Desc()))) + ginkgo.It("returns a job_load_avg15 metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobLoadAvg15Metric).Desc()))) }) - It("returns a job_cpu_sys metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobCPUSysMetric).Desc()))) + ginkgo.It("returns a job_cpu_sys metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobCPUSysMetric).Desc()))) }) - It("returns a job_cpu_user metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobCPUUserMetric).Desc()))) + ginkgo.It("returns a job_cpu_user metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobCPUUserMetric).Desc()))) }) - It("returns a job_cpu_wait metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobCPUWaitMetric).Desc()))) + ginkgo.It("returns a job_cpu_wait metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobCPUWaitMetric).Desc()))) }) - It("returns a job_mem_kb metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobMemKBMetric).Desc()))) + ginkgo.It("returns a job_mem_kb metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobMemKBMetric).Desc()))) }) - It("returns a job_mem_percent metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobMemPercentMetric).Desc()))) + ginkgo.It("returns a job_mem_percent metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobMemPercentMetric).Desc()))) }) - It("returns a job_swap_kb metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobSwapKBMetric).Desc()))) + ginkgo.It("returns a job_swap_kb metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobSwapKBMetric).Desc()))) }) - It("returns a job_swap_percent metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobSwapPercentMetric).Desc()))) + ginkgo.It("returns a job_swap_percent metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobSwapPercentMetric).Desc()))) }) - It("returns a job_system_disk_inode_percent metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobSystemDiskInodePercentMetric).Desc()))) + ginkgo.It("returns a job_system_disk_inode_percent metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobSystemDiskInodePercentMetric).Desc()))) }) - It("returns a job_system_disk_percent metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobSystemDiskPercentMetric).Desc()))) + ginkgo.It("returns a job_system_disk_percent metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobSystemDiskPercentMetric).Desc()))) }) - It("returns a job_ephemeral_disk_inode_percent metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobEphemeralDiskInodePercentMetric).Desc()))) + ginkgo.It("returns a job_ephemeral_disk_inode_percent metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobEphemeralDiskInodePercentMetric).Desc()))) }) - It("returns a job_ephemeral_disk_percent metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobEphemeralDiskPercentMetric).Desc()))) + ginkgo.It("returns a job_ephemeral_disk_percent metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobEphemeralDiskPercentMetric).Desc()))) }) - It("returns a job_persistent_disk_inode_percent metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobPersistentDiskInodePercentMetric).Desc()))) + ginkgo.It("returns a job_persistent_disk_inode_percent metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobPersistentDiskInodePercentMetric).Desc()))) }) - It("returns a job_persistent_disk_percent metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobPersistentDiskPercentMetric).Desc()))) + ginkgo.It("returns a job_persistent_disk_percent metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobPersistentDiskPercentMetric).Desc()))) }) - It("returns a job_process_info metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobProcessInfoMetric, jobProcessName, jobProcessReleaseName, jobProcessReleaseVersion).Desc()))) + ginkgo.It("returns a job_process_info metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobProcessInfoMetric, jobProcessName, jobProcessReleaseName, jobProcessReleaseVersion).Desc()))) }) - It("returns a job_process_healthy metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobProcessHealthyMetric, jobProcessName).Desc()))) + ginkgo.It("returns a job_process_healthy metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobProcessHealthyMetric, jobProcessName).Desc()))) }) - It("returns a job_process_uptime_seconds metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobProcessUptimeMetric, jobProcessName).Desc()))) + ginkgo.It("returns a job_process_uptime_seconds metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobProcessUptimeMetric, jobProcessName).Desc()))) }) - It("returns a job_process_cpu_total metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobProcessCPUTotalMetric, jobProcessName).Desc()))) + ginkgo.It("returns a job_process_cpu_total metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobProcessCPUTotalMetric, jobProcessName).Desc()))) }) - It("returns a job_process_mem_kb metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobProcessMemKBMetric, jobProcessName).Desc()))) + ginkgo.It("returns a job_process_mem_kb metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobProcessMemKBMetric, jobProcessName).Desc()))) }) - It("returns a job_process_mem_percent metric description", func() { - Eventually(descriptions).Should(Receive(Equal(baseLabelValues.AddLabelValues(jobProcessMemPercentMetric, jobProcessName).Desc()))) + ginkgo.It("returns a job_process_mem_percent metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(baseLabelValues.AddLabelValues(jobProcessMemPercentMetric, jobProcessName).Desc()))) }) - It("returns a last_jobs_scrape_timestamp metric description", func() { - Eventually(descriptions).Should(Receive(Equal(lastJobsScrapeTimestampMetric.Desc()))) + ginkgo.It("returns a last_jobs_scrape_timestamp metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(lastJobsScrapeTimestampMetric.Desc()))) }) - It("returns a last_jobs_scrape_duration_seconds metric description", func() { - Eventually(descriptions).Should(Receive(Equal(lastJobsScrapeDurationSecondsMetric.Desc()))) + ginkgo.It("returns a last_jobs_scrape_duration_seconds metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(lastJobsScrapeDurationSecondsMetric.Desc()))) }) }) - Describe("Collect", func() { + ginkgo.Describe("Collect", func() { var ( processes []deployments.Process vitals deployments.Vitals @@ -321,7 +321,7 @@ var _ = Describe("JobsCollector", func() { errMetrics chan error ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { processes = []deployments.Process{ { Name: jobProcessName, @@ -389,7 +389,7 @@ var _ = Describe("JobsCollector", func() { errMetrics = make(chan error, 1) }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { go func() { if err := jobsCollector.Collect(deploymentsInfo, metrics); err != nil { errMetrics <- err @@ -397,405 +397,405 @@ var _ = Describe("JobsCollector", func() { }() }) - It("returns a job_process_healthy metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobHealthyMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_process_healthy metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobHealthyMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when the process is not running", func() { - BeforeEach(func() { + ginkgo.Context("when the process is not running", func() { + ginkgo.BeforeEach(func() { instances[0].Healthy = false baseLabelValues.AddLabelValues(jobHealthyMetric).Set(float64(0)) }) - It("returns a job_process_healthy metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobHealthyMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_process_healthy metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobHealthyMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_load_avg01 metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg01Metric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_load_avg01 metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg01Metric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - It("returns a job_load_avg05 metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg05Metric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_load_avg05 metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg05Metric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - It("returns a job_load_avg15 metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg15Metric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_load_avg15 metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg15Metric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no load avg values", func() { - BeforeEach(func() { + ginkgo.Context("when there is no load avg values", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.Load = []string{} }) - It("does not return any job_load_avg metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg01Metric)))) - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg05Metric)))) - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg15Metric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return any job_load_avg metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg01Metric)))) + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg05Metric)))) + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobLoadAvg15Metric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_cpu_sys metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUSysMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_cpu_sys metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUSysMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no cpu sys value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no cpu sys value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.CPU = deployments.CPU{ User: strconv.FormatFloat(jobCPUUser, 'E', -1, 64), Wait: strconv.FormatFloat(jobCPUWait, 'E', -1, 64), } }) - It("does not return a job_cpu_sys metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUSysMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_cpu_sys metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUSysMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_cpu_user metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUUserMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_cpu_user metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUUserMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no cpu user value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no cpu user value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.CPU = deployments.CPU{ Sys: strconv.FormatFloat(jobCPUSys, 'E', -1, 64), Wait: strconv.FormatFloat(jobCPUWait, 'E', -1, 64), } }) - It("does not return a job_cpu_user metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUUserMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_cpu_user metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUUserMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_cpu_wait metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUWaitMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_cpu_wait metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUWaitMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no cpu wait value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no cpu wait value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.CPU = deployments.CPU{ Sys: strconv.FormatFloat(jobCPUSys, 'E', -1, 64), User: strconv.FormatFloat(jobCPUUser, 'E', -1, 64), } }) - It("does not return a job_cpu_wait metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUWaitMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_cpu_wait metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobCPUWaitMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_mem_kb metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobMemKBMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_mem_kb metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobMemKBMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no mem kb value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no mem kb value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.Mem = deployments.Mem{ Percent: strconv.Itoa(jobMemPercent), } }) - It("does not return a job_mem_kb metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobMemKBMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_mem_kb metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobMemKBMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_mem_percent metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobMemPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_mem_percent metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobMemPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no mem percent value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no mem percent value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.Mem = deployments.Mem{ KB: strconv.Itoa(jobMemKB), } }) - It("does not return a job_mem_percent metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobMemPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_mem_percent metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobMemPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_swap_kb metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobSwapKBMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_swap_kb metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobSwapKBMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no swap kb value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no swap kb value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.Swap = deployments.Mem{ Percent: strconv.Itoa(jobSwapPercent), } }) - It("does not return a job_swap_kb metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobSwapKBMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_swap_kb metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobSwapKBMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_swap_percent metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobSwapPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_swap_percent metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobSwapPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no swap percent value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no swap percent value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.Swap = deployments.Mem{ KB: strconv.Itoa(jobSwapKB), } }) - It("does not return a job_swap_percent metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobSwapPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_swap_percent metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobSwapPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_system_disk_inode_percent metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobSystemDiskInodePercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_system_disk_inode_percent metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobSystemDiskInodePercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no system disk inode percent value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no system disk inode percent value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.SystemDisk = deployments.Disk{ Percent: strconv.Itoa(jobSystemDiskPercent), } }) - It("does not return a job_system_disk_inode_percent metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobSystemDiskInodePercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_system_disk_inode_percent metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobSystemDiskInodePercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_system_disk_percent metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobSystemDiskPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_system_disk_percent metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobSystemDiskPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no system disk percent value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no system disk percent value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.SystemDisk = deployments.Disk{ InodePercent: strconv.Itoa(jobSystemDiskInodePercent), } }) - It("does not return a job_system_disk_percent metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobSystemDiskPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_system_disk_percent metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobSystemDiskPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_ephemeral_disk_inode_percent metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobEphemeralDiskInodePercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_ephemeral_disk_inode_percent metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobEphemeralDiskInodePercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no ephemeral disk inode percent value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no ephemeral disk inode percent value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.EphemeralDisk = deployments.Disk{ Percent: strconv.Itoa(jobEphemeralDiskPercent), } }) - It("does not return a job_ephemeral_disk_inode_percent metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobEphemeralDiskInodePercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_ephemeral_disk_inode_percent metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobEphemeralDiskInodePercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_ephemeral_disk_percent metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobEphemeralDiskPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_ephemeral_disk_percent metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobEphemeralDiskPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no ephemeral disk percent value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no ephemeral disk percent value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.EphemeralDisk = deployments.Disk{ InodePercent: strconv.Itoa(jobEphemeralDiskInodePercent), } }) - It("does not return a job_Ephemeral_disk_percent metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobEphemeralDiskPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_Ephemeral_disk_percent metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobEphemeralDiskPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_persistent_disk_inode_percent metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobPersistentDiskInodePercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_persistent_disk_inode_percent metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobPersistentDiskInodePercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no persistent disk inode percent value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no persistent disk inode percent value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.PersistentDisk = deployments.Disk{ Percent: strconv.Itoa(jobPersistentDiskPercent), } }) - It("does not return a job_persistent_disk_inode_percent metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobPersistentDiskInodePercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_persistent_disk_inode_percent metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobPersistentDiskInodePercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_persistent_disk_percent metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobPersistentDiskPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_persistent_disk_percent metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobPersistentDiskPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no persistent disk percent value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no persistent disk percent value", func() { + ginkgo.BeforeEach(func() { instances[0].Vitals.PersistentDisk = deployments.Disk{ InodePercent: strconv.Itoa(jobPersistentDiskInodePercent), } }) - It("does not return a job_persistent_disk_percent metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobPersistentDiskPercentMetric)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_persistent_disk_percent metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobPersistentDiskPercentMetric)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a healthy job_process_healthy metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessHealthyMetric, jobProcessName)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a healthy job_process_healthy metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessHealthyMetric, jobProcessName)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when a process is not running", func() { - BeforeEach(func() { + ginkgo.Context("when a process is not running", func() { + ginkgo.BeforeEach(func() { instances[0].Processes[0].Healthy = false baseLabelValues.AddLabelValues(jobProcessHealthyMetric, jobProcessName).Set(float64(0)) }) - It("returns an unhealthy job_process_healthy metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessHealthyMetric, jobProcessName)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns an unhealthy job_process_healthy metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessHealthyMetric, jobProcessName)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_process_uptime_seconds metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessUptimeMetric, jobProcessName)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a job_process_uptime_seconds metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessUptimeMetric, jobProcessName)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no process uptime value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no process uptime value", func() { + ginkgo.BeforeEach(func() { instances[0].Processes[0].Uptime = nil }) - It("does not return a job_process_uptime_seconds metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessUptimeMetric, jobProcessName)))) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("does not return a job_process_uptime_seconds metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessUptimeMetric, jobProcessName)))) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_process_cpu_total metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessCPUTotalMetric, + ginkgo.It("returns a job_process_cpu_total metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessCPUTotalMetric, jobProcessName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no process cpu total value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no process cpu total value", func() { + ginkgo.BeforeEach(func() { instances[0].Processes[0].CPU = deployments.CPU{} }) - It("does not return a job_process_cpu_total metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessCPUTotalMetric, + ginkgo.It("does not return a job_process_cpu_total metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessCPUTotalMetric, jobProcessName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_process_mem_kb metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessMemKBMetric, + ginkgo.It("returns a job_process_mem_kb metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessMemKBMetric, jobProcessName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no process mem kb value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no process mem kb value", func() { + ginkgo.BeforeEach(func() { instances[0].Processes[0].Mem = deployments.MemInt{Percent: &jobProcessMemPercent} }) - It("does not return a job_process_mem_kb metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessMemKBMetric, + ginkgo.It("does not return a job_process_mem_kb metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessMemKBMetric, jobProcessName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - It("returns a job_process_mem_percent metric", func() { - Eventually(metrics).Should(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessMemPercentMetric, + ginkgo.It("returns a job_process_mem_percent metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessMemPercentMetric, jobProcessName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there is no process mem percent value", func() { - BeforeEach(func() { + ginkgo.Context("when there is no process mem percent value", func() { + ginkgo.BeforeEach(func() { instances[0].Processes[0].Mem = deployments.MemInt{KB: &jobProcessMemKB} }) - It("does not return a job_process_mem_percent metric", func() { - Consistently(metrics).ShouldNot(Receive(PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessMemPercentMetric, + ginkgo.It("does not return a job_process_mem_percent metric", func() { + gomega.Consistently(metrics).ShouldNot(gomega.Receive(matchers.PrometheusMetric(baseLabelValues.AddLabelValues(jobProcessMemPercentMetric, jobProcessName, )))) - Consistently(errMetrics).ShouldNot(Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - Context("when there are no deployments", func() { - BeforeEach(func() { + ginkgo.Context("when there are no deployments", func() { + ginkgo.BeforeEach(func() { deploymentsInfo = []deployments.DeploymentInfo{} }) - It("returns only a last_jobs_scrape_timestamp & last_jobs_scrape_duration_seconds metric", func() { - Eventually(metrics).Should(Receive()) - Eventually(metrics).Should(Receive()) - Consistently(metrics).ShouldNot(Receive()) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns only a last_jobs_scrape_timestamp & last_jobs_scrape_duration_seconds metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Consistently(metrics).ShouldNot(gomega.Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - Context("when there are no instances", func() { - BeforeEach(func() { + ginkgo.Context("when there are no instances", func() { + ginkgo.BeforeEach(func() { deploymentInfo.Instances = []deployments.Instance{} deploymentsInfo = []deployments.DeploymentInfo{deploymentInfo} }) - It("returns only a last_jobs_scrape_timestamp & last_jobs_scrape_duration_seconds metric", func() { - Eventually(metrics).Should(Receive()) - Eventually(metrics).Should(Receive()) - Consistently(metrics).ShouldNot(Receive()) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns only a last_jobs_scrape_timestamp & last_jobs_scrape_duration_seconds metric", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Consistently(metrics).ShouldNot(gomega.Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) }) diff --git a/collectors/service_discovery_collector_test.go b/collectors/service_discovery_collector_test.go index 8e66c6ae..b68c3197 100644 --- a/collectors/service_discovery_collector_test.go +++ b/collectors/service_discovery_collector_test.go @@ -4,9 +4,9 @@ import ( "encoding/json" "os" - . "github.com/benjamintf1/unmarshalledmatchers" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/benjamintf1/unmarshalledmatchers" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/log" @@ -14,14 +14,14 @@ import ( "github.com/bosh-prometheus/bosh_exporter/deployments" "github.com/bosh-prometheus/bosh_exporter/filters" - . "github.com/bosh-prometheus/bosh_exporter/collectors" + "github.com/bosh-prometheus/bosh_exporter/collectors" ) func init() { _ = log.Base().SetLevel("fatal") } -var _ = Describe("ServiceDiscoveryCollector", func() { +var _ = ginkgo.Describe("ServiceDiscoveryCollector", func() { var ( err error namespace string @@ -33,21 +33,21 @@ var _ = Describe("ServiceDiscoveryCollector", func() { azsFilter *filters.AZsFilter processesFilter *filters.RegexpFilter cidrsFilter *filters.CidrFilter - metrics *ServiceDiscoveryCollectorMetrics - serviceDiscoveryCollector *ServiceDiscoveryCollector + metrics *collectors.ServiceDiscoveryCollectorMetrics + serviceDiscoveryCollector *collectors.ServiceDiscoveryCollector lastServiceDiscoveryScrapeTimestampMetric prometheus.Gauge lastServiceDiscoveryScrapeDurationSecondsMetric prometheus.Gauge ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { namespace = testNamespace environment = testEnvironment boshName = testBoshName boshUUID = testBoshUUID - metrics = NewServiceDiscoveryCollectorMetrics(testNamespace, testEnvironment, testBoshName, testBoshUUID) + metrics = collectors.NewServiceDiscoveryCollectorMetrics(testNamespace, testEnvironment, testBoshName, testBoshUUID) tmpfile, err = os.CreateTemp("", "service_discovery_collector_test_") - Expect(err).ToNot(HaveOccurred()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) serviceDiscoveryFilename = tmpfile.Name() azsFilter = filters.NewAZsFilter([]string{}) cidrsFilter, err = filters.NewCidrFilter([]string{"0.0.0.0/0"}) @@ -57,13 +57,13 @@ var _ = Describe("ServiceDiscoveryCollector", func() { lastServiceDiscoveryScrapeDurationSecondsMetric = metrics.NewLastServiceDiscoveryScrapeDurationSecondsMetric() }) - AfterEach(func() { + ginkgo.AfterEach(func() { err = os.Remove(serviceDiscoveryFilename) - Expect(err).ToNot(HaveOccurred()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) - JustBeforeEach(func() { - serviceDiscoveryCollector = NewServiceDiscoveryCollector( + ginkgo.JustBeforeEach(func() { + serviceDiscoveryCollector = collectors.NewServiceDiscoveryCollector( namespace, environment, boshName, @@ -75,29 +75,29 @@ var _ = Describe("ServiceDiscoveryCollector", func() { ) }) - Describe("Describe", func() { + ginkgo.Describe("ginkgo.Describe", func() { var ( descriptions chan *prometheus.Desc ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { descriptions = make(chan *prometheus.Desc) }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { go serviceDiscoveryCollector.Describe(descriptions) }) - It("returns a last_service_discovery_scrape_timestamp metric description", func() { - Eventually(descriptions).Should(Receive(Equal(lastServiceDiscoveryScrapeTimestampMetric.Desc()))) + ginkgo.It("returns a last_service_discovery_scrape_timestamp metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(lastServiceDiscoveryScrapeTimestampMetric.Desc()))) }) - It("returns a last_service_discovery_scrape_duration_seconds metric description", func() { - Eventually(descriptions).Should(Receive(Equal(lastServiceDiscoveryScrapeDurationSecondsMetric.Desc()))) + ginkgo.It("returns a last_service_discovery_scrape_duration_seconds metric description", func() { + gomega.Eventually(descriptions).Should(gomega.Receive(gomega.Equal(lastServiceDiscoveryScrapeDurationSecondsMetric.Desc()))) }) }) - Describe("Collect", func() { + ginkgo.Describe("Collect", func() { var ( deployment1Name = "fake-deployment-1-name" deployment2Name = "fake-deployment-2-name" @@ -161,7 +161,7 @@ var _ = Describe("ServiceDiscoveryCollector", func() { errMetrics chan error ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { deployment1Processes = []deployments.Process{ { Name: jobProcess1Name, @@ -220,7 +220,7 @@ var _ = Describe("ServiceDiscoveryCollector", func() { errMetrics = make(chan error, 1) }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { go func() { if err := serviceDiscoveryCollector.Collect(deploymentsInfo, metrics); err != nil { errMetrics <- err @@ -228,120 +228,120 @@ var _ = Describe("ServiceDiscoveryCollector", func() { }() }) - It("writes a target groups file", func() { - Eventually(metrics).Should(Receive()) + ginkgo.It("writes a target groups file", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) targetGroups, err := os.ReadFile(serviceDiscoveryFilename) - Expect(err).ToNot(HaveOccurred()) - Expect(string(targetGroups)).To(MatchUnorderedJSON(targetGroupsContent)) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Expect(string(targetGroups)).To(unmarshalledmatchers.MatchUnorderedJSON(targetGroupsContent)) }) - It("returns a last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { - Eventually(metrics).Should(Receive()) - Eventually(metrics).Should(Receive()) - Consistently(metrics).ShouldNot(Receive()) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns a last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Consistently(metrics).ShouldNot(gomega.Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) - Context("when there are no deployments", func() { - BeforeEach(func() { + ginkgo.Context("when there are no deployments", func() { + ginkgo.BeforeEach(func() { deploymentsInfo = []deployments.DeploymentInfo{} }) - It("writes an empty target groups file", func() { - Eventually(metrics).Should(Receive()) + ginkgo.It("writes an empty target groups file", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) targetGroups, err := os.ReadFile(serviceDiscoveryFilename) - Expect(err).ToNot(HaveOccurred()) - Expect(string(targetGroups)).To(Equal("[]")) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Expect(string(targetGroups)).To(gomega.Equal("[]")) }) - It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { - Eventually(metrics).Should(Receive()) - Eventually(metrics).Should(Receive()) - Consistently(metrics).ShouldNot(Receive()) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Consistently(metrics).ShouldNot(gomega.Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - Context("when there are no instances", func() { - BeforeEach(func() { + ginkgo.Context("when there are no instances", func() { + ginkgo.BeforeEach(func() { deployment1Info.Instances = []deployments.Instance{} deploymentsInfo = []deployments.DeploymentInfo{deployment1Info} }) - It("writes an empty target groups file", func() { - Eventually(metrics).Should(Receive()) + ginkgo.It("writes an empty target groups file", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) targetGroups, err := os.ReadFile(serviceDiscoveryFilename) - Expect(err).ToNot(HaveOccurred()) - Expect(string(targetGroups)).To(Equal("[]")) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Expect(string(targetGroups)).To(gomega.Equal("[]")) }) - It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { - Eventually(metrics).Should(Receive()) - Eventually(metrics).Should(Receive()) - Consistently(metrics).ShouldNot(Receive()) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Consistently(metrics).ShouldNot(gomega.Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - Context("when instance has no IP", func() { - BeforeEach(func() { + ginkgo.Context("when instance has no IP", func() { + ginkgo.BeforeEach(func() { deployment1Info.Instances[0].IPs = []string{} deploymentsInfo = []deployments.DeploymentInfo{deployment1Info} }) - It("writes an empty target groups file", func() { - Eventually(metrics).Should(Receive()) + ginkgo.It("writes an empty target groups file", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) targetGroups, err := os.ReadFile(serviceDiscoveryFilename) - Expect(err).ToNot(HaveOccurred()) - Expect(string(targetGroups)).To(Equal("[]")) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Expect(string(targetGroups)).To(gomega.Equal("[]")) }) - It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { - Eventually(metrics).Should(Receive()) - Eventually(metrics).Should(Receive()) - Consistently(metrics).ShouldNot(Receive()) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Consistently(metrics).ShouldNot(gomega.Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - Context("when no IP is found for an instance", func() { - BeforeEach(func() { + ginkgo.Context("when no IP is found for an instance", func() { + ginkgo.BeforeEach(func() { cidrsFilter, err = filters.NewCidrFilter([]string{"10.254.0.0/16"}) }) - It("writes an empty target groups file", func() { - Eventually(metrics).Should(Receive()) + ginkgo.It("writes an empty target groups file", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) targetGroups, err := os.ReadFile(serviceDiscoveryFilename) - Expect(err).ToNot(HaveOccurred()) - Expect(string(targetGroups)).To(Equal("[]")) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Expect(string(targetGroups)).To(gomega.Equal("[]")) }) - It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { - Eventually(metrics).Should(Receive()) - Eventually(metrics).Should(Receive()) - Consistently(metrics).ShouldNot(Receive()) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Consistently(metrics).ShouldNot(gomega.Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) - Context("when there are no processes", func() { - BeforeEach(func() { + ginkgo.Context("when there are no processes", func() { + ginkgo.BeforeEach(func() { deployment1Info.Instances[0].Processes = []deployments.Process{} deploymentsInfo = []deployments.DeploymentInfo{deployment1Info} }) - It("writes an empty target groups file", func() { - Eventually(metrics).Should(Receive()) + ginkgo.It("writes an empty target groups file", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) targetGroups, err := os.ReadFile(serviceDiscoveryFilename) - Expect(err).ToNot(HaveOccurred()) - Expect(string(targetGroups)).To(Equal("[]")) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Expect(string(targetGroups)).To(gomega.Equal("[]")) }) - It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { - Eventually(metrics).Should(Receive()) - Eventually(metrics).Should(Receive()) - Consistently(metrics).ShouldNot(Receive()) - Consistently(errMetrics).ShouldNot(Receive()) + ginkgo.It("returns only last_service_discovery_scrape_timestamp & last_service_discovery_scrape_duration_seconds", func() { + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Eventually(metrics).Should(gomega.Receive()) + gomega.Consistently(metrics).ShouldNot(gomega.Receive()) + gomega.Consistently(errMetrics).ShouldNot(gomega.Receive()) }) }) }) diff --git a/deployments/deployments_fetcher_test.go b/deployments/deployments_fetcher_test.go index 29233338..866a7a50 100644 --- a/deployments/deployments_fetcher_test.go +++ b/deployments/deployments_fetcher_test.go @@ -4,8 +4,8 @@ import ( "errors" "strconv" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "github.com/cloudfoundry/bosh-cli/director" "github.com/cloudfoundry/bosh-cli/director/directorfakes" @@ -14,33 +14,33 @@ import ( "github.com/bosh-prometheus/bosh_exporter/filters" - . "github.com/bosh-prometheus/bosh_exporter/deployments" + "github.com/bosh-prometheus/bosh_exporter/deployments" ) func init() { _ = log.Base().SetLevel("fatal") } -var _ = Describe("Fetcher", func() { +var _ = ginkgo.Describe("Fetcher", func() { var ( err error boshDeployments []string boshClient *directorfakes.FakeDirector deploymentsFilter *filters.DeploymentsFilter - deploymentsFetcher *Fetcher + deploymentsFetcher *deployments.Fetcher ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { boshDeployments = []string{} boshClient = &directorfakes.FakeDirector{} }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { deploymentsFilter = filters.NewDeploymentsFilter(boshDeployments, boshClient) - deploymentsFetcher = NewFetcher(*deploymentsFilter) + deploymentsFetcher = deployments.NewFetcher(*deploymentsFilter) }) - Describe("Deployments", func() { + ginkgo.Describe("Deployments", func() { var ( deploymentName = "fake-deployment-name" agentID = "fake-agent-id" @@ -88,21 +88,21 @@ var _ = Describe("Fetcher", func() { stemcellVersion = "4.5.6" stemcellOSName = "fake-stemcell-os-name" - processes []director.VMInfoProcess - vitals director.VMInfoVitals - instances []director.VMInfo - release director.Release - releases []director.Release - stemcell director.Stemcell - stemcells []director.Stemcell - deployments []director.Deployment - deployment director.Deployment - - deploymentsInfo []DeploymentInfo - expectedDeploymentsInfo []DeploymentInfo + processes []director.VMInfoProcess + vitals director.VMInfoVitals + instances []director.VMInfo + release director.Release + releases []director.Release + stemcell director.Stemcell + stemcells []director.Stemcell + depls []director.Deployment + deployment director.Deployment + + deploymentsInfo []deployments.DeploymentInfo + expectedDeploymentsInfo []deployments.DeploymentInfo ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { processes = []director.VMInfoProcess{ { Name: jobProcessName, @@ -196,13 +196,13 @@ var _ = Describe("Fetcher", func() { StemcellsStub: func() ([]director.Stemcell, error) { return stemcells, nil }, } - deployments = []director.Deployment{deployment} - boshClient.DeploymentsReturns(deployments, nil) + depls = []director.Deployment{deployment} + boshClient.DeploymentsReturns(depls, nil) - expectedDeploymentsInfo = []DeploymentInfo{ + expectedDeploymentsInfo = []deployments.DeploymentInfo{ { Name: deploymentName, - Instances: []Instance{ + Instances: []deployments.Instance{ { AgentID: agentID, Name: jobName, @@ -215,26 +215,26 @@ var _ = Describe("Fetcher", func() { ResourcePool: jobResourcePool, ResurrectionPaused: jobResurrectionPause, Healthy: true, - Processes: []Process{ + Processes: []deployments.Process{ { Name: jobProcessName, Uptime: &jobProcessUptimeSeconds, Healthy: true, - CPU: CPU{Total: &jobProcessCPUTotal}, - Mem: MemInt{KB: &jobProcessMemKB, Percent: &jobProcessMemPercent}, + CPU: deployments.CPU{Total: &jobProcessCPUTotal}, + Mem: deployments.MemInt{KB: &jobProcessMemKB, Percent: &jobProcessMemPercent}, }, }, - Vitals: Vitals{ - CPU: CPU{ + Vitals: deployments.Vitals{ + CPU: deployments.CPU{ Sys: strconv.FormatFloat(jobCPUSys, 'E', -1, 64), User: strconv.FormatFloat(jobCPUUser, 'E', -1, 64), Wait: strconv.FormatFloat(jobCPUWait, 'E', -1, 64), }, - Mem: Mem{ + Mem: deployments.Mem{ KB: strconv.Itoa(jobMemKB), Percent: strconv.Itoa(jobMemPercent), }, - Swap: Mem{ + Swap: deployments.Mem{ KB: strconv.Itoa(jobSwapKB), Percent: strconv.Itoa(jobSwapPercent), }, @@ -244,179 +244,179 @@ var _ = Describe("Fetcher", func() { strconv.FormatFloat(jobLoadAvg05, 'E', -1, 64), strconv.FormatFloat(jobLoadAvg15, 'E', -1, 64), }, - SystemDisk: Disk{ + SystemDisk: deployments.Disk{ InodePercent: strconv.Itoa(jobSystemDiskInodePercent), Percent: strconv.Itoa(jobSystemDiskPercent), }, - EphemeralDisk: Disk{ + EphemeralDisk: deployments.Disk{ InodePercent: strconv.Itoa(jobEphemeralDiskInodePercent), Percent: strconv.Itoa(jobEphemeralDiskPercent), }, - PersistentDisk: Disk{ + PersistentDisk: deployments.Disk{ InodePercent: strconv.Itoa(jobPersistentDiskInodePercent), Percent: strconv.Itoa(jobPersistentDiskPercent), }, }, }, }, - Releases: []Release{ + Releases: []deployments.Release{ {Name: releaseName, Version: releaseVersion, JobNames: []string{releaseJob1Name, releaseJob2Name}, PackageNames: []string{releasePackage1Name, releasePackage2Name}, }, }, - Stemcells: []Stemcell{ + Stemcells: []deployments.Stemcell{ {Name: stemcellName, Version: stemcellVersion, OSName: stemcellOSName}, }, }, } }) - JustBeforeEach(func() { + ginkgo.JustBeforeEach(func() { deploymentsInfo, err = deploymentsFetcher.Deployments() }) - It("returns the deployments", func() { - Expect(deploymentsInfo).To(Equal(expectedDeploymentsInfo)) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("returns the deployments", func() { + gomega.Expect(deploymentsInfo).To(gomega.Equal(expectedDeploymentsInfo)) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) - Context("when instance has no VMID", func() { - BeforeEach(func() { + ginkgo.Context("when instance has no VMID", func() { + ginkgo.BeforeEach(func() { instances[0].VMID = "" deployment = &directorfakes.FakeDeployment{ NameStub: func() string { return deploymentName }, ReleasesStub: func() ([]director.Release, error) { return releases, nil }, StemcellsStub: func() ([]director.Stemcell, error) { return stemcells, nil }, } - deployments = []director.Deployment{deployment} - boshClient.DeploymentsReturns(deployments, nil) + depls = []director.Deployment{deployment} + boshClient.DeploymentsReturns(depls, nil) }) - It("does not return the instance", func() { - Expect(deploymentsInfo[0].Instances).To(BeEmpty()) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return the instance", func() { + gomega.Expect(deploymentsInfo[0].Instances).To(gomega.BeEmpty()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when there are no deployments", func() { - BeforeEach(func() { + ginkgo.Context("when there are no deployments", func() { + ginkgo.BeforeEach(func() { boshClient.DeploymentsReturns([]director.Deployment{}, nil) }) - It("does not return deployments", func() { - Expect(deploymentsInfo).To(BeEmpty()) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return deployments", func() { + gomega.Expect(deploymentsInfo).To(gomega.BeEmpty()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when it fails to get the deployment", func() { - BeforeEach(func() { + ginkgo.Context("when it fails to get the deployment", func() { + ginkgo.BeforeEach(func() { boshClient.DeploymentsReturns([]director.Deployment{}, errors.New("no deployments")) }) - It("does not return deployments", func() { - Expect(deploymentsInfo).To(BeEmpty()) - Expect(err).To(HaveOccurred()) + ginkgo.It("does not return deployments", func() { + gomega.Expect(deploymentsInfo).To(gomega.BeEmpty()) + gomega.Expect(err).To(gomega.HaveOccurred()) }) }) - Context("when there are no instances", func() { - BeforeEach(func() { + ginkgo.Context("when there are no instances", func() { + ginkgo.BeforeEach(func() { deployment = &directorfakes.FakeDeployment{ NameStub: func() string { return deploymentName }, ReleasesStub: func() ([]director.Release, error) { return releases, nil }, StemcellsStub: func() ([]director.Stemcell, error) { return stemcells, nil }, } - deployments = []director.Deployment{deployment} - boshClient.DeploymentsReturns(deployments, nil) + depls = []director.Deployment{deployment} + boshClient.DeploymentsReturns(depls, nil) }) - It("does not return instances", func() { - Expect(deploymentsInfo[0].Instances).To(BeEmpty()) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return instances", func() { + gomega.Expect(deploymentsInfo[0].Instances).To(gomega.BeEmpty()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when it fails to get the deployment instances", func() { - BeforeEach(func() { + ginkgo.Context("when it fails to get the deployment instances", func() { + ginkgo.BeforeEach(func() { deployment = &directorfakes.FakeDeployment{ NameStub: func() string { return deploymentName }, InstanceInfosStub: func() ([]director.VMInfo, error) { return nil, errors.New("no instances") }, } - deployments = []director.Deployment{deployment} - boshClient.DeploymentsReturns(deployments, nil) + depls = []director.Deployment{deployment} + boshClient.DeploymentsReturns(depls, nil) }) - It("does not return deployments", func() { - Expect(deploymentsInfo).To(BeEmpty()) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return deployments", func() { + gomega.Expect(deploymentsInfo).To(gomega.BeEmpty()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when there are no releases", func() { - BeforeEach(func() { + ginkgo.Context("when there are no releases", func() { + ginkgo.BeforeEach(func() { deployment = &directorfakes.FakeDeployment{ NameStub: func() string { return deploymentName }, InstanceInfosStub: func() ([]director.VMInfo, error) { return instances, nil }, StemcellsStub: func() ([]director.Stemcell, error) { return stemcells, nil }, } - deployments = []director.Deployment{deployment} - boshClient.DeploymentsReturns(deployments, nil) + depls = []director.Deployment{deployment} + boshClient.DeploymentsReturns(depls, nil) }) - It("does not return releases", func() { - Expect(deploymentsInfo[0].Releases).To(BeEmpty()) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return releases", func() { + gomega.Expect(deploymentsInfo[0].Releases).To(gomega.BeEmpty()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when it fails to get the deployment releases", func() { - BeforeEach(func() { + ginkgo.Context("when it fails to get the deployment releases", func() { + ginkgo.BeforeEach(func() { deployment = &directorfakes.FakeDeployment{ NameStub: func() string { return deploymentName }, ReleasesStub: func() ([]director.Release, error) { return nil, errors.New("no releases") }, } - deployments = []director.Deployment{deployment} - boshClient.DeploymentsReturns(deployments, nil) + depls = []director.Deployment{deployment} + boshClient.DeploymentsReturns(depls, nil) }) - It("does not return deployments", func() { - Expect(deploymentsInfo).To(BeEmpty()) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return deployments", func() { + gomega.Expect(deploymentsInfo).To(gomega.BeEmpty()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when there are no stemcells", func() { - BeforeEach(func() { + ginkgo.Context("when there are no stemcells", func() { + ginkgo.BeforeEach(func() { deployment = &directorfakes.FakeDeployment{ NameStub: func() string { return deploymentName }, InstanceInfosStub: func() ([]director.VMInfo, error) { return instances, nil }, ReleasesStub: func() ([]director.Release, error) { return releases, nil }, } - deployments = []director.Deployment{deployment} - boshClient.DeploymentsReturns(deployments, nil) + depls = []director.Deployment{deployment} + boshClient.DeploymentsReturns(depls, nil) }) - It("does not return stemcells", func() { - Expect(deploymentsInfo[0].Stemcells).To(BeEmpty()) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return stemcells", func() { + gomega.Expect(deploymentsInfo[0].Stemcells).To(gomega.BeEmpty()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when it fails to get the deployment stemcells", func() { - BeforeEach(func() { + ginkgo.Context("when it fails to get the deployment stemcells", func() { + ginkgo.BeforeEach(func() { deployment = &directorfakes.FakeDeployment{ NameStub: func() string { return deploymentName }, StemcellsStub: func() ([]director.Stemcell, error) { return nil, errors.New("no stemcells") }, } - deployments = []director.Deployment{deployment} - boshClient.DeploymentsReturns(deployments, nil) + depls = []director.Deployment{deployment} + boshClient.DeploymentsReturns(depls, nil) }) - It("does not return deployments", func() { - Expect(deploymentsInfo).To(BeEmpty()) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return deployments", func() { + gomega.Expect(deploymentsInfo).To(gomega.BeEmpty()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) }) diff --git a/deployments/deployments_suite_test.go b/deployments/deployments_suite_test.go index f60223ec..796c2192 100644 --- a/deployments/deployments_suite_test.go +++ b/deployments/deployments_suite_test.go @@ -1,13 +1,13 @@ package deployments_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "testing" ) func TestDeployments(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Deployments Suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Deployments Suite") } diff --git a/filters/azs_filter_test.go b/filters/azs_filter_test.go index 248e54bb..d254d31f 100644 --- a/filters/azs_filter_test.go +++ b/filters/azs_filter_test.go @@ -1,56 +1,56 @@ package filters_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" - . "github.com/bosh-prometheus/bosh_exporter/filters" + "github.com/bosh-prometheus/bosh_exporter/filters" ) -var _ = Describe("AZsFilter", func() { +var _ = ginkgo.Describe("AZsFilter", func() { var ( filter []string - azsFilter *AZsFilter + azsFilter *filters.AZsFilter ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { filter = []string{"fake-az-1", "fake-az-3"} }) - JustBeforeEach(func() { - azsFilter = NewAZsFilter(filter) + ginkgo.JustBeforeEach(func() { + azsFilter = filters.NewAZsFilter(filter) }) - Describe("Enabled", func() { - Context("when az is enabled", func() { - It("returns true", func() { - Expect(azsFilter.Enabled("fake-az-1")).To(BeTrue()) + ginkgo.Describe("Enabled", func() { + ginkgo.Context("when az is enabled", func() { + ginkgo.It("returns true", func() { + gomega.Expect(azsFilter.Enabled("fake-az-1")).To(gomega.BeTrue()) }) }) - Context("when az is not enabled", func() { - It("returns false", func() { - Expect(azsFilter.Enabled("fake-az-2")).To(BeFalse()) + ginkgo.Context("when az is not enabled", func() { + ginkgo.It("returns false", func() { + gomega.Expect(azsFilter.Enabled("fake-az-2")).To(gomega.BeFalse()) }) }) - Context("when there is no filter", func() { - BeforeEach(func() { + ginkgo.Context("when there is no filter", func() { + ginkgo.BeforeEach(func() { filter = []string{} }) - It("returns true", func() { - Expect(azsFilter.Enabled("fake-az-2")).To(BeTrue()) + ginkgo.It("returns true", func() { + gomega.Expect(azsFilter.Enabled("fake-az-2")).To(gomega.BeTrue()) }) }) - Context("when a filter has leading and/or trailing whitespaces", func() { - BeforeEach(func() { + ginkgo.Context("when a filter has leading and/or trailing whitespaces", func() { + ginkgo.BeforeEach(func() { filter = []string{" fake-az-1 "} }) - It("returns true", func() { - Expect(azsFilter.Enabled("fake-az-1")).To(BeTrue()) + ginkgo.It("returns true", func() { + gomega.Expect(azsFilter.Enabled("fake-az-1")).To(gomega.BeTrue()) }) }) }) diff --git a/filters/cidr_filter_test.go b/filters/cidr_filter_test.go index 711b9b38..ea77509d 100644 --- a/filters/cidr_filter_test.go +++ b/filters/cidr_filter_test.go @@ -1,117 +1,117 @@ package filters_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" - . "github.com/bosh-prometheus/bosh_exporter/filters" + "github.com/bosh-prometheus/bosh_exporter/filters" ) -var _ = Describe("Cidr Filter", func() { +var _ = ginkgo.Describe("Cidr Filter", func() { var ( err error cidrs []string - cidrFilter *CidrFilter + cidrFilter *filters.CidrFilter ) - JustBeforeEach(func() { - cidrFilter, err = NewCidrFilter(cidrs) + ginkgo.JustBeforeEach(func() { + cidrFilter, err = filters.NewCidrFilter(cidrs) }) - Describe("New", func() { - Context("when valid cidr", func() { - BeforeEach(func() { + ginkgo.Describe("New", func() { + ginkgo.Context("when valid cidr", func() { + ginkgo.BeforeEach(func() { cidrs = []string{"0.0.0.0/0", "10.250.0.0/16"} }) - It("does not return an error", func() { - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return an error", func() { + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when invalid cidr", func() { - BeforeEach(func() { + ginkgo.Context("when invalid cidr", func() { + ginkgo.BeforeEach(func() { cidrs = []string{"not.a.cidr"} }) - It("returns an error", func() { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal("invalid CIDR address: not.a.cidr")) + ginkgo.It("returns an error", func() { + gomega.Expect(err).To(gomega.HaveOccurred()) + gomega.Expect(err.Error()).To(gomega.Equal("invalid CIDR address: not.a.cidr")) }) }) }) - Describe("Select", func() { - Describe("with default cidr", func() { - BeforeEach(func() { + ginkgo.Describe("Select", func() { + ginkgo.Describe("with default cidr", func() { + ginkgo.BeforeEach(func() { cidrs = []string{"0.0.0.0/0"} }) - Context("when selecting single ip", func() { - It("returns first ip/true", func() { + ginkgo.Context("when selecting single ip", func() { + ginkgo.It("returns first ip/true", func() { ip, found := cidrFilter.Select([]string{"192.168.0.1"}) - Expect(found).To(BeTrue()) - Expect(ip).To(Equal("192.168.0.1")) + gomega.Expect(found).To(gomega.BeTrue()) + gomega.Expect(ip).To(gomega.Equal("192.168.0.1")) }) }) - Context("when selecting multiple ips", func() { - It("returns first ip/true", func() { + ginkgo.Context("when selecting multiple ips", func() { + ginkgo.It("returns first ip/true", func() { ip, found := cidrFilter.Select([]string{"192.168.0.1", "10.254.12.57"}) - Expect(found).To(BeTrue()) - Expect(ip).To(Equal("192.168.0.1")) + gomega.Expect(found).To(gomega.BeTrue()) + gomega.Expect(ip).To(gomega.Equal("192.168.0.1")) }) }) - Context("when selecting empty list", func() { - It("returns empty/false", func() { + ginkgo.Context("when selecting empty list", func() { + ginkgo.It("returns empty/false", func() { ip, found := cidrFilter.Select([]string{}) - Expect(found).To(BeFalse()) - Expect(ip).To(Equal("")) + gomega.Expect(found).To(gomega.BeFalse()) + gomega.Expect(ip).To(gomega.Equal("")) }) }) }) - Describe("with multiple cidr", func() { - BeforeEach(func() { + ginkgo.Describe("with multiple cidr", func() { + ginkgo.BeforeEach(func() { cidrs = []string{"10.254.0.0/16", "0.0.0.0/0"} }) - Context("when selecting single ip", func() { - It("returns first ip/true", func() { + ginkgo.Context("when selecting single ip", func() { + ginkgo.It("returns first ip/true", func() { ip, found := cidrFilter.Select([]string{"192.168.0.1"}) - Expect(found).To(BeTrue()) - Expect(ip).To(Equal("192.168.0.1")) + gomega.Expect(found).To(gomega.BeTrue()) + gomega.Expect(ip).To(gomega.Equal("192.168.0.1")) }) }) - Context("when selecting multiple ips", func() { - It("returns second ip/true", func() { + ginkgo.Context("when selecting multiple ips", func() { + ginkgo.It("returns second ip/true", func() { ip, found := cidrFilter.Select([]string{"192.168.0.1", "10.254.12.57"}) - Expect(found).To(BeTrue()) - Expect(ip).To(Equal("10.254.12.57")) + gomega.Expect(found).To(gomega.BeTrue()) + gomega.Expect(ip).To(gomega.Equal("10.254.12.57")) }) }) }) - Describe("with specific cidr", func() { - BeforeEach(func() { + ginkgo.Describe("with specific cidr", func() { + ginkgo.BeforeEach(func() { cidrs = []string{"10.254.0.0/16"} }) - Context("with matching ip", func() { - It("returns first ip/true", func() { + ginkgo.Context("with matching ip", func() { + ginkgo.It("returns first ip/true", func() { ip, found := cidrFilter.Select([]string{"10.254.1.1"}) - Expect(found).To(BeTrue()) - Expect(ip).To(Equal("10.254.1.1")) + gomega.Expect(found).To(gomega.BeTrue()) + gomega.Expect(ip).To(gomega.Equal("10.254.1.1")) }) }) - Context("with unmatching ip", func() { - It("returns empty/false", func() { + ginkgo.Context("with unmatching ip", func() { + ginkgo.It("returns empty/false", func() { ip, found := cidrFilter.Select([]string{"192.168.0.1"}) - Expect(found).To(BeFalse()) - Expect(ip).To(Equal("")) + gomega.Expect(found).To(gomega.BeFalse()) + gomega.Expect(ip).To(gomega.Equal("")) }) }) }) diff --git a/filters/collectors_filter_test.go b/filters/collectors_filter_test.go index 9fdbaa60..9bf76fea 100644 --- a/filters/collectors_filter_test.go +++ b/filters/collectors_filter_test.go @@ -1,81 +1,81 @@ package filters_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" - . "github.com/bosh-prometheus/bosh_exporter/filters" + "github.com/bosh-prometheus/bosh_exporter/filters" ) -var _ = Describe("CollectorsFilter", func() { +var _ = ginkgo.Describe("CollectorsFilter", func() { var ( - err error - filters []string + err error + filtersArray []string - collectorsFilter *CollectorsFilter + collectorsFilter *filters.CollectorsFilter ) - JustBeforeEach(func() { - collectorsFilter, err = NewCollectorsFilter(filters) + ginkgo.JustBeforeEach(func() { + collectorsFilter, err = filters.NewCollectorsFilter(filtersArray) }) - Describe("New", func() { - Context("when filters are supported", func() { - BeforeEach(func() { - filters = []string{DeploymentsCollector, JobsCollector, ServiceDiscoveryCollector} + ginkgo.Describe("New", func() { + ginkgo.Context("when filters are supported", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{filters.DeploymentsCollector, filters.JobsCollector, filters.ServiceDiscoveryCollector} }) - It("does not return an error", func() { - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return an error", func() { + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when filters are not supported", func() { - BeforeEach(func() { - filters = []string{DeploymentsCollector, JobsCollector, "Unknown"} + ginkgo.Context("when filters are not supported", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{filters.DeploymentsCollector, filters.JobsCollector, "Unknown"} }) - It("returns an error", func() { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal("collector filter `Unknown` is not supported")) + ginkgo.It("returns an error", func() { + gomega.Expect(err).To(gomega.HaveOccurred()) + gomega.Expect(err.Error()).To(gomega.Equal("collector filter `Unknown` is not supported")) }) }) - Context("when a filter has leading and/or trailing whitespaces", func() { - BeforeEach(func() { - filters = []string{" " + DeploymentsCollector + " "} + ginkgo.Context("when a filter has leading and/or trailing whitespaces", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{" " + filters.DeploymentsCollector + " "} }) - It("returns an error", func() { - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("returns an error", func() { + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) }) - Describe("Enabled", func() { - BeforeEach(func() { - filters = []string{DeploymentsCollector} + ginkgo.Describe("Enabled", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{filters.DeploymentsCollector} }) - Context("when collector is enabled", func() { - It("returns true", func() { - Expect(collectorsFilter.Enabled(DeploymentsCollector)).To(BeTrue()) + ginkgo.Context("when collector is enabled", func() { + ginkgo.It("returns true", func() { + gomega.Expect(collectorsFilter.Enabled(filters.DeploymentsCollector)).To(gomega.BeTrue()) }) }) - Context("when collector is not enabled", func() { - It("returns false", func() { - Expect(collectorsFilter.Enabled(JobsCollector)).To(BeFalse()) + ginkgo.Context("when collector is not enabled", func() { + ginkgo.It("returns false", func() { + gomega.Expect(collectorsFilter.Enabled(filters.JobsCollector)).To(gomega.BeFalse()) }) }) - Context("when there are no filters", func() { - BeforeEach(func() { - filters = []string{} + ginkgo.Context("when there are no filters", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{} }) - It("returns true", func() { - Expect(collectorsFilter.Enabled(JobsCollector)).To(BeTrue()) + ginkgo.It("returns true", func() { + gomega.Expect(collectorsFilter.Enabled(filters.JobsCollector)).To(gomega.BeTrue()) }) }) }) diff --git a/filters/deployments_filter_test.go b/filters/deployments_filter_test.go index a9981b6b..7efe1ba2 100644 --- a/filters/deployments_filter_test.go +++ b/filters/deployments_filter_test.go @@ -3,29 +3,29 @@ package filters_test import ( "errors" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "github.com/cloudfoundry/bosh-cli/director" "github.com/cloudfoundry/bosh-cli/director/directorfakes" "github.com/prometheus/common/log" - . "github.com/bosh-prometheus/bosh_exporter/filters" + "github.com/bosh-prometheus/bosh_exporter/filters" ) func init() { _ = log.Base().SetLevel("fatal") } -var _ = Describe("DeploymentsFilter", func() { +var _ = ginkgo.Describe("DeploymentsFilter", func() { var ( err error - filters []string + filtersArray []string boshClient *directorfakes.FakeDirector - deploymentsFilter *DeploymentsFilter + deploymentsFilter *filters.DeploymentsFilter ) - Describe("GetDeployments", func() { + ginkgo.Describe("GetDeployments", func() { var ( deployment1 director.Deployment deployment2 director.Deployment @@ -34,8 +34,8 @@ var _ = Describe("DeploymentsFilter", func() { deployments []director.Deployment ) - BeforeEach(func() { - filters = []string{} + ginkgo.BeforeEach(func() { + filtersArray = []string{} boshClient = &directorfakes.FakeDirector{} deployment1 = &directorfakes.FakeDeployment{ @@ -47,78 +47,78 @@ var _ = Describe("DeploymentsFilter", func() { allDeployments = []director.Deployment{} }) - JustBeforeEach(func() { - deploymentsFilter = NewDeploymentsFilter(filters, boshClient) + ginkgo.JustBeforeEach(func() { + deploymentsFilter = filters.NewDeploymentsFilter(filtersArray, boshClient) deployments, err = deploymentsFilter.GetDeployments() }) - Context("when there are no filters", func() { - BeforeEach(func() { + ginkgo.Context("when there are no filters", func() { + ginkgo.BeforeEach(func() { boshClient.DeploymentsReturns(allDeployments, nil) }) - It("returns all deployments", func() { - Expect(deployments).To(Equal(allDeployments)) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("returns all deployments", func() { + gomega.Expect(deployments).To(gomega.Equal(allDeployments)) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) - Context("and there are no deployments", func() { - BeforeEach(func() { + ginkgo.Context("and there are no deployments", func() { + ginkgo.BeforeEach(func() { boshClient.DeploymentsReturns([]director.Deployment{}, nil) }) - It("does not return any deployment", func() { - Expect(deployments).To(BeEmpty()) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return any deployment", func() { + gomega.Expect(deployments).To(gomega.BeEmpty()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("and it fails to get the deployments", func() { - BeforeEach(func() { + ginkgo.Context("and it fails to get the deployments", func() { + ginkgo.BeforeEach(func() { boshClient.DeploymentsReturns(nil, errors.New("no deployments")) }) - It("does not return any deployment", func() { - Expect(deployments).To(BeEmpty()) - Expect(err).To(HaveOccurred()) + ginkgo.It("does not return any deployment", func() { + gomega.Expect(deployments).To(gomega.BeEmpty()) + gomega.Expect(err).To(gomega.HaveOccurred()) }) }) }) - Context("when there are filters", func() { - BeforeEach(func() { - filters = []string{"fake-deployment-name-1"} + ginkgo.Context("when there are filters", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{"fake-deployment-name-1"} boshClient.FindDeploymentReturns(deployment1, nil) }) - It("returns the filtered deployments", func() { - Expect(boshClient.FindDeploymentArgsForCall(0)).To(Equal("fake-deployment-name-1")) - Expect(deployments).To(ContainElement(deployment1)) - Expect(deployments).ToNot(ContainElement(deployment2)) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("returns the filtered deployments", func() { + gomega.Expect(boshClient.FindDeploymentArgsForCall(0)).To(gomega.Equal("fake-deployment-name-1")) + gomega.Expect(deployments).To(gomega.ContainElement(deployment1)) + gomega.Expect(deployments).ToNot(gomega.ContainElement(deployment2)) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) - Context("and it fails to get the deployment", func() { - BeforeEach(func() { + ginkgo.Context("and it fails to get the deployment", func() { + ginkgo.BeforeEach(func() { boshClient.FindDeploymentReturns(nil, errors.New("deployment does not exists")) }) - It("does not return any deployment", func() { - Expect(deployments).To(BeEmpty()) - Expect(err).To(HaveOccurred()) + ginkgo.It("does not return any deployment", func() { + gomega.Expect(deployments).To(gomega.BeEmpty()) + gomega.Expect(err).To(gomega.HaveOccurred()) }) }) - Context("and the deployment name has leading and/or trailing whitespaces", func() { - BeforeEach(func() { - filters = []string{" fake-deployment-name-1 "} + ginkgo.Context("and the deployment name has leading and/or trailing whitespaces", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{" fake-deployment-name-1 "} }) - It("returns the filtered deployments", func() { - Expect(boshClient.FindDeploymentArgsForCall(0)).To(Equal("fake-deployment-name-1")) - Expect(deployments).To(ContainElement(deployment1)) - Expect(deployments).ToNot(ContainElement(deployment2)) - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("returns the filtered deployments", func() { + gomega.Expect(boshClient.FindDeploymentArgsForCall(0)).To(gomega.Equal("fake-deployment-name-1")) + gomega.Expect(deployments).To(gomega.ContainElement(deployment1)) + gomega.Expect(deployments).ToNot(gomega.ContainElement(deployment2)) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) }) diff --git a/filters/filters_suite_test.go b/filters/filters_suite_test.go index 8db9e042..dc5fe244 100644 --- a/filters/filters_suite_test.go +++ b/filters/filters_suite_test.go @@ -1,13 +1,13 @@ package filters_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "testing" ) func TestFilters(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Filters Suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Filters Suite") } diff --git a/filters/regexp_filter_test.go b/filters/regexp_filter_test.go index bc2a3375..c2bee84a 100644 --- a/filters/regexp_filter_test.go +++ b/filters/regexp_filter_test.go @@ -1,71 +1,71 @@ package filters_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" - . "github.com/bosh-prometheus/bosh_exporter/filters" + "github.com/bosh-prometheus/bosh_exporter/filters" ) -var _ = Describe("RegexpFilter", func() { +var _ = ginkgo.Describe("RegexpFilter", func() { var ( - err error - filters []string + err error + filtersArray []string - regexpFilter *RegexpFilter + regexpFilter *filters.RegexpFilter ) - JustBeforeEach(func() { - regexpFilter, err = NewRegexpFilter(filters) + ginkgo.JustBeforeEach(func() { + regexpFilter, err = filters.NewRegexpFilter(filtersArray) }) - Describe("New", func() { - Context("when filters compile", func() { - BeforeEach(func() { - filters = []string{"bosh_exporter", "[a-z]+_collector"} + ginkgo.Describe("New", func() { + ginkgo.Context("when filters compile", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{"bosh_exporter", "[a-z]+_collector"} }) - It("does not return an error", func() { - Expect(err).ToNot(HaveOccurred()) + ginkgo.It("does not return an error", func() { + gomega.Expect(err).ToNot(gomega.HaveOccurred()) }) }) - Context("when filters does not compile", func() { - BeforeEach(func() { - filters = []string{"[a-(z]+_exporter"} + ginkgo.Context("when filters does not compile", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{"[a-(z]+_exporter"} }) - It("returns an error", func() { - Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(Equal("error parsing regexp: invalid character class range: `a-(`")) + ginkgo.It("returns an error", func() { + gomega.Expect(err).To(gomega.HaveOccurred()) + gomega.Expect(err.Error()).To(gomega.Equal("error parsing regexp: invalid character class range: `a-(`")) }) }) }) - Describe("Enabled", func() { - BeforeEach(func() { - filters = []string{"bosh_exporter", "[a-z]+_collector"} + ginkgo.Describe("Enabled", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{"bosh_exporter", "[a-z]+_collector"} }) - Context("when there is a match", func() { - It("returns true", func() { - Expect(regexpFilter.Enabled("deployments_collector")).To(BeTrue()) + ginkgo.Context("when there is a match", func() { + ginkgo.It("returns true", func() { + gomega.Expect(regexpFilter.Enabled("deployments_collector")).To(gomega.BeTrue()) }) }) - Context("when there is not a match", func() { - It("returns false", func() { - Expect(regexpFilter.Enabled("deployments_exporter")).To(BeFalse()) + ginkgo.Context("when there is not a match", func() { + ginkgo.It("returns false", func() { + gomega.Expect(regexpFilter.Enabled("deployments_exporter")).To(gomega.BeFalse()) }) }) - Context("when there are no filters", func() { - BeforeEach(func() { - filters = []string{} + ginkgo.Context("when there are no filters", func() { + ginkgo.BeforeEach(func() { + filtersArray = []string{} }) - It("returns true", func() { - Expect(regexpFilter.Enabled("deployments_exporter")).To(BeTrue()) + ginkgo.It("returns true", func() { + gomega.Expect(regexpFilter.Enabled("deployments_exporter")).To(gomega.BeTrue()) }) }) }) diff --git a/utils/matchers/prometheus_metric_matcher_test.go b/utils/matchers/prometheus_metric_matcher_test.go index 554be82c..9a565fd0 100644 --- a/utils/matchers/prometheus_metric_matcher_test.go +++ b/utils/matchers/prometheus_metric_matcher_test.go @@ -1,15 +1,15 @@ package matchers_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "github.com/prometheus/client_golang/prometheus" - . "github.com/bosh-prometheus/bosh_exporter/utils/matchers" + "github.com/bosh-prometheus/bosh_exporter/utils/matchers" ) -var _ = Describe("PrometheusMetric", func() { +var _ = ginkgo.Describe("matchers.PrometheusMetric", func() { var ( metricNamespace = "fake_namespace" metricSubsystem = "fake_sybsystem" @@ -21,8 +21,8 @@ var _ = Describe("PrometheusMetric", func() { metricConstLabelValue = "fake_constant_label_value" ) - Context("When asserting equality between Counter Metrics", func() { - It("should do the right thing", func() { + ginkgo.Context("When asserting equality between Counter Metrics", func() { + ginkgo.It("should do the right thing", func() { expectedMetric := prometheus.NewCounter( prometheus.CounterOpts{ Namespace: metricNamespace, @@ -43,12 +43,12 @@ var _ = Describe("PrometheusMetric", func() { }) actualMetric.Inc() - Expect(expectedMetric).To(PrometheusMetric(actualMetric)) + gomega.Expect(expectedMetric).To(matchers.PrometheusMetric(actualMetric)) }) }) - Context("When asserting equality between CounterVec Metrics", func() { - It("should do the right thing", func() { + ginkgo.Context("When asserting equality between CounterVec Metrics", func() { + ginkgo.It("should do the right thing", func() { expectedMetric := prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: metricNamespace, @@ -73,12 +73,12 @@ var _ = Describe("PrometheusMetric", func() { ) actualMetric.WithLabelValues(metricLabelValue).Inc() - Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue))) + gomega.Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(matchers.PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue))) }) }) - Context("When asserting equality between Gauge Metrics", func() { - It("should do the right thing", func() { + ginkgo.Context("When asserting equality between Gauge Metrics", func() { + ginkgo.It("should do the right thing", func() { expectedMetric := prometheus.NewGauge( prometheus.GaugeOpts{ Namespace: metricNamespace, @@ -99,12 +99,12 @@ var _ = Describe("PrometheusMetric", func() { }) actualMetric.Inc() - Expect(expectedMetric).To(PrometheusMetric(actualMetric)) + gomega.Expect(expectedMetric).To(matchers.PrometheusMetric(actualMetric)) }) }) - Context("When asserting equality between GaugeVec Metrics", func() { - It("should do the right thing", func() { + ginkgo.Context("When asserting equality between GaugeVec Metrics", func() { + ginkgo.It("should do the right thing", func() { expectedMetric := prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: metricNamespace, @@ -129,12 +129,12 @@ var _ = Describe("PrometheusMetric", func() { ) actualMetric.WithLabelValues(metricLabelValue).Inc() - Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue))) + gomega.Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(matchers.PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue))) }) }) - Context("When asserting equality between Histogram Metrics", func() { - It("should do the right thing", func() { + ginkgo.Context("When asserting equality between Histogram Metrics", func() { + ginkgo.It("should do the right thing", func() { expectedMetric := prometheus.NewHistogram( prometheus.HistogramOpts{ Namespace: metricNamespace, @@ -155,12 +155,12 @@ var _ = Describe("PrometheusMetric", func() { }) actualMetric.Observe(float64(1)) - Expect(expectedMetric).To(PrometheusMetric(actualMetric)) + gomega.Expect(expectedMetric).To(matchers.PrometheusMetric(actualMetric)) }) }) - Context("When asserting equality between HistogramVec Metrics", func() { - It("should do the right thing", func() { + ginkgo.Context("When asserting equality between HistogramVec Metrics", func() { + ginkgo.It("should do the right thing", func() { expectedMetric := prometheus.NewHistogramVec( prometheus.HistogramOpts{ Namespace: metricNamespace, @@ -185,12 +185,12 @@ var _ = Describe("PrometheusMetric", func() { ) actualMetric.WithLabelValues(metricLabelValue).Observe(float64(1)) - Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue).(prometheus.Histogram))) + gomega.Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(matchers.PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue).(prometheus.Histogram))) }) }) - Context("When asserting equality between Summary Metrics", func() { - It("should do the right thing", func() { + ginkgo.Context("When asserting equality between Summary Metrics", func() { + ginkgo.It("should do the right thing", func() { expectedMetric := prometheus.NewSummary( prometheus.SummaryOpts{ Namespace: metricNamespace, @@ -211,12 +211,12 @@ var _ = Describe("PrometheusMetric", func() { }) actualMetric.Observe(float64(1)) - Expect(expectedMetric).To(PrometheusMetric(actualMetric)) + gomega.Expect(expectedMetric).To(matchers.PrometheusMetric(actualMetric)) }) }) - Context("When asserting equality between SummaryVec Metrics", func() { - It("should do the right thing", func() { + ginkgo.Context("When asserting equality between SummaryVec Metrics", func() { + ginkgo.It("should do the right thing", func() { expectedMetric := prometheus.NewSummaryVec( prometheus.SummaryOpts{ Namespace: metricNamespace, @@ -241,7 +241,7 @@ var _ = Describe("PrometheusMetric", func() { ) actualMetric.WithLabelValues(metricLabelValue).Observe(float64(1)) - Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue).(prometheus.Summary))) + gomega.Expect(expectedMetric.WithLabelValues(metricLabelValue)).To(matchers.PrometheusMetric(actualMetric.WithLabelValues(metricLabelValue).(prometheus.Summary))) }) }) }) diff --git a/utils/matchers/test_matchers_suite_test.go b/utils/matchers/test_matchers_suite_test.go index 91b4714f..ed284121 100644 --- a/utils/matchers/test_matchers_suite_test.go +++ b/utils/matchers/test_matchers_suite_test.go @@ -1,13 +1,13 @@ package matchers_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" "testing" ) func TestCollectors(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Test Matchers Suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Test Matchers Suite") }