From a85833ae53ea08e3eb72989209c1012a07cf878f Mon Sep 17 00:00:00 2001 From: Max Eshleman Date: Tue, 26 Feb 2019 11:34:50 -0700 Subject: [PATCH] replace gomega with require in prometheus output client tests Signed-off-by: Robert Sullivan --- Gopkg.lock | 22 ------- .../prometheus_client_tls_test.go | 61 ++++++------------- 2 files changed, 18 insertions(+), 65 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index c3c980f65..c07c288c0 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -821,27 +821,6 @@ revision = "eee57a3ac4174c55924125bb15eeeda8cffb6e6f" version = "v1.0.7" -[[projects]] - digest = "1:c8f0c8c28c9c1c51db72d0e7f04797cfe5d0d50528274099b6b2d6c314db7f97" - name = "github.com/onsi/gomega" - packages = [ - ".", - "format", - "internal/assertion", - "internal/asyncassertion", - "internal/oraclematcher", - "internal/testingtsupport", - "matchers", - "matchers/support/goraph/bipartitegraph", - "matchers/support/goraph/edge", - "matchers/support/goraph/node", - "matchers/support/goraph/util", - "types", - ] - pruneopts = "" - revision = "65fb64232476ad9046e57c26cd0bff3d3a8dc6cd" - version = "v1.4.3" - [[projects]] digest = "1:5d9b668b0b4581a978f07e7d2e3314af18eb27b3fb5d19b70185b7c575723d11" name = "github.com/opencontainers/go-digest" @@ -1589,7 +1568,6 @@ "github.com/nats-io/gnatsd/server", "github.com/nats-io/go-nats", "github.com/nsqio/go-nsq", - "github.com/onsi/gomega", "github.com/openzipkin/zipkin-go-opentracing", "github.com/openzipkin/zipkin-go-opentracing/thrift/gen-go/zipkincore", "github.com/prometheus/client_golang/prometheus", diff --git a/plugins/outputs/prometheus_client/prometheus_client_tls_test.go b/plugins/outputs/prometheus_client/prometheus_client_tls_test.go index 4658fcdb4..d7484d61f 100644 --- a/plugins/outputs/prometheus_client/prometheus_client_tls_test.go +++ b/plugins/outputs/prometheus_client/prometheus_client_tls_test.go @@ -6,7 +6,7 @@ import ( "github.com/influxdata/telegraf/plugins/outputs/prometheus_client" "github.com/influxdata/telegraf/testutil" "github.com/influxdata/toml" - . "github.com/onsi/gomega" + "github.com/stretchr/testify/require" "net/http" "testing" ) @@ -28,8 +28,6 @@ type PrometheusClientTestContext struct { Output *prometheus_client.PrometheusClient Accumulator *testutil.Accumulator Client *http.Client - - *GomegaWithT } func TestWorksWithoutTLS(t *testing.T) { @@ -37,47 +35,29 @@ func TestWorksWithoutTLS(t *testing.T) { err := tc.Output.Connect() defer tc.Output.Close() - if err != nil { - panic(err) - } + require.NoError(t, err) - var response *http.Response - tc.Eventually(func() bool { - response, err = tc.Client.Get("http://localhost:9090/metrics") - return err == nil - }, "5s").Should(BeTrue()) + response, err := tc.Client.Get("http://localhost:9090/metrics") + require.NoError(t, err) - if err != nil { - panic(err) - } - - tc.Expect(response.StatusCode).To(Equal(http.StatusOK)) + require.NoError(t, err) + require.Equal(t, response.StatusCode, http.StatusOK) } func TestWorksWithTLS(t *testing.T) { tc := buildTestContext(t, []byte(configWithTLS)) err := tc.Output.Connect() defer tc.Output.Close() + require.NoError(t, err) - if err != nil { - panic(err) - } + response, err := tc.Client.Get("https://localhost:9090/metrics") + require.NoError(t, err) - var response *http.Response - tc.Eventually(func() bool { - response, err = tc.Client.Get("https://localhost:9090/metrics") - return err == nil - }, "5s").Should(BeTrue()) - - if err != nil { - panic(err) - } - - tc.Expect(response.StatusCode).To(Equal(http.StatusOK)) + require.NoError(t, err) + require.Equal(t, response.StatusCode, http.StatusOK) response, err = tc.Client.Get("http://localhost:9090/metrics") - - tc.Expect(err).To(HaveOccurred()) + require.Error(t, err) tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, @@ -86,23 +66,20 @@ func TestWorksWithTLS(t *testing.T) { client := &http.Client{Transport: tr} response, err = client.Get("https://localhost:9090/metrics") - tc.Expect(err).To(HaveOccurred()) + require.Error(t, err) } func buildTestContext(t *testing.T, config []byte) *PrometheusClientTestContext { output := prometheus_client.NewClient() err := toml.Unmarshal(config, output) - - if err != nil { - panic(err) - } + require.NoError(t, err) var ( httpClient *http.Client ) if len(output.TLSAllowedCACerts) != 0 { - httpClient = buildClientWithTLS(output) + httpClient = buildClientWithTLS(t, output) } else { httpClient = buildClientWithoutTLS() } @@ -111,7 +88,6 @@ func buildTestContext(t *testing.T, config []byte) *PrometheusClientTestContext Output: output, Accumulator: &testutil.Accumulator{}, Client: httpClient, - GomegaWithT: NewGomegaWithT(t), } } @@ -119,11 +95,10 @@ func buildClientWithoutTLS() *http.Client { return &http.Client{} } -func buildClientWithTLS(output *prometheus_client.PrometheusClient) *http.Client { +func buildClientWithTLS(t *testing.T, output *prometheus_client.PrometheusClient) *http.Client { tlsConfig, err := pki.TLSClientConfig().TLSConfig() - if err != nil { - panic(err) - } + require.NoError(t, err) + transport := &http.Transport{TLSClientConfig: tlsConfig} return &http.Client{Transport: transport} }