-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dominik Rosiek <[email protected]>
- Loading branch information
Dominik Rosiek
committed
Apr 22, 2024
1 parent
ce2d146
commit 907a13a
Showing
8 changed files
with
486 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,88 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package sumologicexporter | ||
package sumologicexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumologicexporter" | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
) | ||
|
||
func TestFieldsAsString(t *testing.T) { | ||
expected := "key1=value1, key2=value2, key3=value3" | ||
flds := fieldsFromMap(map[string]string{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "value2", | ||
}) | ||
func TestFields(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
fields map[string]string | ||
expected string | ||
}{ | ||
{ | ||
name: "string", | ||
fields: map[string]string{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "value2", | ||
}, | ||
expected: "key1=value1, key2=value2, key3=value3", | ||
}, | ||
{ | ||
name: "sanitization", | ||
fields: map[string]string{ | ||
"key1": "value,1", | ||
"key3": "value\n3", | ||
"key=,2": "valu,e=2", | ||
}, | ||
expected: "key1=value_1, key3=value_3, key:_2=valu_e:2", | ||
}, | ||
{ | ||
name: "empty element", | ||
fields: map[string]string{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "", | ||
}, | ||
expected: "key1=value1, key3=value3", | ||
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
flds := fieldsFromMap(tc.fields) | ||
|
||
assert.Equal(t, expected, flds.string()) | ||
assert.Equal(t, tc.expected, flds.string()) | ||
}) | ||
} | ||
} | ||
|
||
func TestFieldsSanitization(t *testing.T) { | ||
expected := "key1=value_1, key3=value_3, key:_2=valu_e:2" | ||
flds := fieldsFromMap(map[string]string{ | ||
"key1": "value,1", | ||
"key3": "value\n3", | ||
"key=,2": "valu,e=2", | ||
}) | ||
func BenchmarkFields(b *testing.B) { | ||
attrMap := pcommon.NewMap() | ||
flds := map[string]any{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "", | ||
"map": map[string]string{ | ||
"key1": "value1", | ||
"key3": "value3", | ||
"key2": "", | ||
}, | ||
} | ||
for k, v := range flds { | ||
switch v := v.(type) { | ||
case string: | ||
attrMap.PutStr(k, v) | ||
case map[string]string: | ||
m := pcommon.NewValueMap() | ||
mm := m.Map().AsRaw() | ||
for kk, vv := range v { | ||
mm[kk] = vv | ||
} | ||
m.CopyTo(attrMap.PutEmpty(k)) | ||
} | ||
} | ||
sut := newFields(attrMap) | ||
|
||
assert.Equal(t, expected, flds.string()) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = sut.string() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.