From 2f2c5ff985841833533a4d3908b9c7e11b20618a Mon Sep 17 00:00:00 2001 From: Jiri Tyr Date: Wed, 21 Mar 2018 23:38:09 +0000 Subject: [PATCH] Exclude test flags from the public API --- plugins/inputs/ssl_cert/ssl_cert.go | 14 ++++++++------ plugins/inputs/ssl_cert/ssl_cert_test.go | 9 +++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/inputs/ssl_cert/ssl_cert.go b/plugins/inputs/ssl_cert/ssl_cert.go index f28b7d832f8d0..e56d17038a062 100644 --- a/plugins/inputs/ssl_cert/ssl_cert.go +++ b/plugins/inputs/ssl_cert/ssl_cert.go @@ -29,12 +29,14 @@ type SSLCert struct { Servers []string `toml:"servers"` Files []string `toml:"files"` Timeout time.Duration `toml:"timeout"` - - // For tests - CloseConn bool - UnsetCerts bool } +// For tests +var ( + closeConn bool + unsetCerts bool +) + // Description returns description of the plugin. func (sc *SSLCert) Description() string { return description @@ -45,7 +47,7 @@ func (sc *SSLCert) SampleConfig() string { return sampleConfig } -func getRemoteCert(server string, timeout time.Duration, closeConn bool, unsetCerts bool) (*x509.Certificate, error) { +func getRemoteCert(server string, timeout time.Duration) (*x509.Certificate, error) { tlsCfg := &tls.Config{ InsecureSkipVerify: true, } @@ -121,7 +123,7 @@ func (sc *SSLCert) Gather(acc telegraf.Accumulator) error { now := time.Now() for _, server := range sc.Servers { - cert, err := getRemoteCert(server, sc.Timeout*time.Second, sc.CloseConn, sc.UnsetCerts) + cert, err := getRemoteCert(server, sc.Timeout*time.Second) if err != nil { return fmt.Errorf("cannot get remote SSL cert '%s': %s", server, err) } diff --git a/plugins/inputs/ssl_cert/ssl_cert_test.go b/plugins/inputs/ssl_cert/ssl_cert_test.go index 5e7ce4bb41363..32c0dd93615ca 100644 --- a/plugins/inputs/ssl_cert/ssl_cert_test.go +++ b/plugins/inputs/ssl_cert/ssl_cert_test.go @@ -121,12 +121,13 @@ func TestGatherRemote(t *testing.T) { } sc := SSLCert{ - Servers: []string{test.server}, - Timeout: test.timeout, - CloseConn: test.close, - UnsetCerts: test.unset, + Servers: []string{test.server}, + Timeout: test.timeout, } + closeConn = test.close + unsetCerts = test.unset + error := false acc := testutil.Accumulator{}