Skip to content

Commit

Permalink
[pkg/stanza] Remove deprecated test functions from operatortest
Browse files Browse the repository at this point in the history
This PR completes the migration to operatortest's new confmap-based
unmarshaling strategy. All preexisting usages of operatortest have
been migrated to the new format. The changes here are just to remove
the old code and remaining usages of it.
  • Loading branch information
djaglowski committed Sep 27, 2022
1 parent 1d620bf commit 74a9c0a
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 293 deletions.
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)
}
File renamed without changes.
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.

0 comments on commit 74a9c0a

Please sign in to comment.