Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pkg/stanza] Remove deprecated test functions from operatortest #14542

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 0 additions & 74 deletions pkg/stanza/fileconsumer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"
"time"

"github.com/mitchellh/mapstructure"
"github.com/stretchr/testify/require"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
Expand Down Expand Up @@ -505,76 +504,3 @@ func TestBuild(t *testing.T) {
})
}
}

func NewTestConfig() *Config {
cfg := NewConfig()
cfg.Include = []string{"i1", "i2"}
cfg.Exclude = []string{"e1", "e2"}
cfg.Splitter = helper.NewSplitterConfig()
cfg.Splitter.Multiline = helper.MultilineConfig{
LineStartPattern: "start",
LineEndPattern: "end",
}
cfg.FingerprintSize = 1024
cfg.Splitter.EncodingConfig = helper.EncodingConfig{Encoding: "utf16"}
return cfg
}

func TestMapStructureDecodeConfigWithHook(t *testing.T) {
expect := NewTestConfig()
cfgMap := map[string]interface{}{
"attributes": map[string]interface{}{},
"resource": map[string]interface{}{},
"include": expect.Include,
"exclude": expect.Exclude,
"poll_interval": 200 * time.Millisecond,
"multiline": map[string]interface{}{
"line_start_pattern": expect.Splitter.Multiline.LineStartPattern,
"line_end_pattern": expect.Splitter.Multiline.LineEndPattern,
},
"force_flush_period": 500 * time.Millisecond,
"include_file_name": true,
"include_file_path": false,
"start_at": "end",
"fingerprint_size": "1024",
"max_log_size": "1mib",
"max_concurrent_files": 1024,
"encoding": "utf16",
}

var actual Config
dc := &mapstructure.DecoderConfig{Result: &actual, DecodeHook: operatortest.JSONUnmarshalerHook()}
ms, err := mapstructure.NewDecoder(dc)
require.NoError(t, err)
err = ms.Decode(cfgMap)
require.NoError(t, err)
require.Equal(t, expect, &actual)
}

func TestMapStructureDecodeConfig(t *testing.T) {
expect := NewTestConfig()
cfgMap := map[string]interface{}{
"attributes": map[string]interface{}{},
"resource": map[string]interface{}{},
"include": expect.Include,
"exclude": expect.Exclude,
"poll_interval": 200 * time.Millisecond,
"multiline": map[string]interface{}{
"line_start_pattern": expect.Splitter.Multiline.LineStartPattern,
"line_end_pattern": expect.Splitter.Multiline.LineEndPattern,
},
"include_file_name": true,
"include_file_path": false,
"start_at": "end",
"fingerprint_size": 1024,
"max_log_size": 1024 * 1024,
"max_concurrent_files": 1024,
"encoding": "utf16",
"force_flush_period": 500 * time.Millisecond,
}

var actual Config
err := mapstructure.Decode(cfgMap, &actual)
require.NoError(t, err)
require.Equal(t, expect, &actual)
}
2 changes: 1 addition & 1 deletion pkg/stanza/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/bmatcuk/doublestar/v3 v3.0.0
github.com/jpillora/backoff v1.0.0
github.com/json-iterator/go v1.1.12
github.com/mitchellh/mapstructure v1.5.0
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/observiq/ctimefmt v1.0.0
github.com/observiq/nanojack v0.0.0-20201106172433-343928847ebc
github.com/stretchr/testify v1.8.0
Expand Down
80 changes: 0 additions & 80 deletions pkg/stanza/operator/input/file/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"
"time"

"github.com/mitchellh/mapstructure"
"github.com/stretchr/testify/require"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
Expand Down Expand Up @@ -673,82 +672,3 @@ func requireSamePreEmitOptions(t *testing.T, expect, actual []preEmitOption) {
require.Equal(t, expectFuncName, actualFuncName)
}
}

func NewTestConfig() *Config {
cfg := NewConfigWithID("config_test")
cfg.Include = []string{"i1", "i2"}
cfg.Exclude = []string{"e1", "e2"}
cfg.Splitter = helper.NewSplitterConfig()
cfg.Splitter.Multiline = helper.MultilineConfig{
LineStartPattern: "start",
LineEndPattern: "end",
}
cfg.FingerprintSize = 1024
cfg.Splitter.EncodingConfig = helper.EncodingConfig{Encoding: "utf16"}
return cfg
}

func TestMapStructureDecodeConfigWithHook(t *testing.T) {
expect := NewTestConfig()
input := map[string]interface{}{
// Config
"id": "config_test",
"type": "file_input",
"attributes": map[string]interface{}{},
"resource": map[string]interface{}{},
"include": expect.Include,
"exclude": expect.Exclude,
"poll_interval": 200 * time.Millisecond,
"multiline": map[string]interface{}{
"line_start_pattern": expect.Splitter.Multiline.LineStartPattern,
"line_end_pattern": expect.Splitter.Multiline.LineEndPattern,
},
"force_flush_period": 500 * time.Millisecond,
"include_file_name": true,
"include_file_path": false,
"start_at": "end",
"fingerprint_size": "1024",
"max_log_size": "1mib",
"max_concurrent_files": 1024,
"encoding": "utf16",
}

var actual Config
dc := &mapstructure.DecoderConfig{Result: &actual, DecodeHook: operatortest.JSONUnmarshalerHook()}
ms, err := mapstructure.NewDecoder(dc)
require.NoError(t, err)
err = ms.Decode(input)
require.NoError(t, err)
require.Equal(t, expect, &actual)
}

func TestMapStructureDecodeConfig(t *testing.T) {
expect := NewTestConfig()
input := map[string]interface{}{
// Config
"id": "config_test",
"type": "file_input",
"attributes": map[string]interface{}{},
"resource": map[string]interface{}{},
"include": expect.Include,
"exclude": expect.Exclude,
"poll_interval": 200 * time.Millisecond,
"multiline": map[string]interface{}{
"line_start_pattern": expect.Splitter.Multiline.LineStartPattern,
"line_end_pattern": expect.Splitter.Multiline.LineEndPattern,
},
"include_file_name": true,
"include_file_path": false,
"start_at": "end",
"fingerprint_size": 1024,
"max_log_size": 1024 * 1024,
"max_concurrent_files": 1024,
"encoding": "utf16",
"force_flush_period": 500 * time.Millisecond,
}

var actual Config
err := mapstructure.Decode(input, &actual)
require.NoError(t, err)
require.Equal(t, expect, &actual)
}
52 changes: 0 additions & 52 deletions pkg/stanza/operator/operatortest/mapstructure.go

This file was deleted.

86 changes: 0 additions & 86 deletions pkg/stanza/operator/operatortest/operatortest.go

This file was deleted.