Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
test(recombine): add config tests
Browse files Browse the repository at this point in the history
This adds a basic test plus tests for the new `combine_with` option.
  • Loading branch information
andrzej-stencel committed Nov 29, 2021
1 parent 94e3bed commit 2b4a948
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 0 deletions.
94 changes: 94 additions & 0 deletions operator/builtin/transformer/recombine/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package recombine

import (
"testing"

"github.com/open-telemetry/opentelemetry-log-collection/operator/helper/operatortest"
)

func TestConfig(t *testing.T) {
cases := []operatortest.ConfigUnmarshalTest{
{
Name: "default",
ExpectErr: false,
Expect: defaultCfg(),
},
{
Name: "custom_id",
ExpectErr: false,
Expect: func() *RecombineOperatorConfig {
cfg := defaultCfg()
cfg.OperatorID = "merge-split-lines"
return cfg
}(),
},
{
Name: "combine_with_custom_string",
ExpectErr: false,
Expect: func() *RecombineOperatorConfig {
cfg := defaultCfg()
cfg.CombineWith = "ABC"
return cfg
}(),
},
{
Name: "combine_with_empty_string",
ExpectErr: false,
Expect: func() *RecombineOperatorConfig {
cfg := defaultCfg()
cfg.CombineWith = ""
return cfg
}(),
},
{
Name: "combine_with_tab",
ExpectErr: false,
Expect: func() *RecombineOperatorConfig {
cfg := defaultCfg()
cfg.CombineWith = "\t"
return cfg
}(),
},
{
Name: "combine_with_backslash_t",
ExpectErr: false,
Expect: func() *RecombineOperatorConfig {
cfg := defaultCfg()
cfg.CombineWith = "\\t"
return cfg
}(),
},
{
Name: "combine_with_multiline_string",
ExpectErr: false,
Expect: func() *RecombineOperatorConfig {
cfg := defaultCfg()
cfg.CombineWith = "line1\nLINE2"
return cfg
}(),
},
}
for _, tc := range cases {
t.Run(tc.Name, func(t *testing.T) {
tc.Run(t, defaultCfg())
})
}
}

func defaultCfg() *RecombineOperatorConfig {
return NewRecombineOperatorConfig("recombine")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type: recombine
combine_with: \t
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type: recombine
combine_with: ABC
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type: recombine
combine_with:
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type: recombine
combine_with: "line1\nLINE2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type: recombine
combine_with: "\t"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type: recombine
id: merge-split-lines
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type: recombine

0 comments on commit 2b4a948

Please sign in to comment.