Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
mackjmr committed Oct 4, 2024
1 parent 52c4b7b commit 1293369
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
41 changes: 18 additions & 23 deletions exporter/splunkhecexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package splunkhecexporter

import (
"net/http"
"path/filepath"
"testing"
"time"
Expand All @@ -14,7 +13,6 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/confmap/confmaptest"
Expand All @@ -26,8 +24,6 @@ import (
)

func TestLoadConfig(t *testing.T) {
defaultMaxConnsPerHost := http.DefaultTransport.(*http.Transport).MaxConnsPerHost

t.Parallel()

cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
Expand All @@ -41,6 +37,23 @@ func TestLoadConfig(t *testing.T) {
hundred := 100
idleConnTimeout := 10 * time.Second

clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Timeout = 10 * time.Second
clientConfig.Endpoint = "https://splunk:8088/services/collector"
clientConfig.TLSSetting = configtls.ClientConfig{
Config: configtls.Config{
CAFile: "",
CertFile: "",
KeyFile: "",
},
InsecureSkipVerify: false,
}
clientConfig.HTTP2PingTimeout = 10 * time.Second
clientConfig.HTTP2ReadIdleTimeout = 10 * time.Second
clientConfig.MaxIdleConns = &hundred
clientConfig.MaxIdleConnsPerHost = &hundred
clientConfig.IdleConnTimeout = &idleConnTimeout

tests := []struct {
id component.ID
expected component.Config
Expand All @@ -65,25 +78,7 @@ func TestLoadConfig(t *testing.T) {
MaxContentLengthLogs: 2 * 1024 * 1024,
MaxContentLengthMetrics: 2 * 1024 * 1024,
MaxContentLengthTraces: 2 * 1024 * 1024,
ClientConfig: confighttp.ClientConfig{
Timeout: 10 * time.Second,
Endpoint: "https://splunk:8088/services/collector",
TLSSetting: configtls.ClientConfig{
Config: configtls.Config{
CAFile: "",
CertFile: "",
KeyFile: "",
},
InsecureSkipVerify: false,
},
MaxIdleConns: &hundred,
MaxIdleConnsPerHost: &hundred,
IdleConnTimeout: &idleConnTimeout,
HTTP2ReadIdleTimeout: 10 * time.Second,
HTTP2PingTimeout: 10 * time.Second,
Headers: map[string]configopaque.String{},
MaxConnsPerHost: &defaultMaxConnsPerHost,
},
ClientConfig: clientConfig,
BackOffConfig: configretry.BackOffConfig{
Enabled: true,
InitialInterval: 10 * time.Second,
Expand Down
17 changes: 9 additions & 8 deletions exporter/splunkhecexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ func TestCreateInstanceViaFactory(t *testing.T) {
}

func TestFactory_CreateMetricsExporter(t *testing.T) {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "https://example.com:8000"
config := &Config{
Token: "testToken",
ClientConfig: confighttp.ClientConfig{
Endpoint: "https://example.com:8000",
},
Token: "testToken",
ClientConfig: clientConfig,
}

params := exportertest.NewNopSettings()
Expand All @@ -91,11 +91,12 @@ func TestFactory_CreateMetricsExporter(t *testing.T) {
}

func TestFactory_EnabledBatchingMakesExporterMutable(t *testing.T) {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "https://example.com:8000"

config := &Config{
Token: "testToken",
ClientConfig: confighttp.ClientConfig{
Endpoint: "https://example.com:8000",
},
Token: "testToken",
ClientConfig: clientConfig,
}

me, err := createMetricsExporter(context.Background(), exportertest.NewNopSettings(), config)
Expand Down

0 comments on commit 1293369

Please sign in to comment.