| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package batchprocessor |
| 5 |
|
| 6 |
import ( |
| 7 |
"path/filepath" |
| 8 |
"testing" |
| 9 |
"time" |
| 10 |
|
| 11 |
"github.com/stretchr/testify/assert" |
| 12 |
"github.com/stretchr/testify/require" |
| 13 |
|
| 14 |
"go.opentelemetry.io/collector/confmap" |
| 15 |
"go.opentelemetry.io/collector/confmap/confmaptest" |
| 16 |
) |
| 17 |
|
| 18 |
func TestUnmarshalDefaultConfig(t *testing.T) { |
| 19 |
factory := NewFactory() |
| 20 |
cfg := factory.CreateDefaultConfig() |
| 21 |
require.NoError(t, confmap.New().Unmarshal(&cfg)) |
| 22 |
assert.Equal(t, factory.CreateDefaultConfig(), cfg) |
| 23 |
} |
| 24 |
|
| 25 |
func TestUnmarshalConfig(t *testing.T) { |
| 26 |
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) |
| 27 |
require.NoError(t, err) |
| 28 |
factory := NewFactory() |
| 29 |
cfg := factory.CreateDefaultConfig() |
| 30 |
require.NoError(t, cm.Unmarshal(&cfg)) |
| 31 |
assert.Equal(t, |
| 32 |
&Config{ |
| 33 |
SendBatchSize: uint32(10000), |
| 34 |
SendBatchMaxSize: uint32(11000), |
| 35 |
Timeout: time.Second * 10, |
| 36 |
MetadataCardinalityLimit: 1000, |
| 37 |
}, cfg) |
| 38 |
} |
| 39 |
|
| 40 |
func TestValidateConfig_DefaultBatchMaxSize(t *testing.T) { |
| 41 |
cfg := &Config{ |
| 42 |
SendBatchSize: 100, |
| 43 |
SendBatchMaxSize: 0, |
| 44 |
} |
| 45 |
assert.NoError(t, cfg.Validate()) |
| 46 |
} |
| 47 |
|
| 48 |
func TestValidateConfig_ValidBatchSizes(t *testing.T) { |
| 49 |
cfg := &Config{ |
| 50 |
SendBatchSize: 100, |
| 51 |
SendBatchMaxSize: 1000, |
| 52 |
} |
| 53 |
assert.NoError(t, cfg.Validate()) |
| 54 |
} |
| 55 |
|
| 56 |
func TestValidateConfig_InvalidBatchSize(t *testing.T) { |
| 57 |
cfg := &Config{ |
| 58 |
SendBatchSize: 1000, |
| 59 |
SendBatchMaxSize: 100, |
| 60 |
} |
| 61 |
assert.Error(t, cfg.Validate()) |
| 62 |
} |
| 63 |
|
| 64 |
func TestValidateConfig_InvalidTimeout(t *testing.T) { |
| 65 |
cfg := &Config{ |
| 66 |
Timeout: -time.Second, |
| 67 |
} |
| 68 |
assert.Error(t, cfg.Validate()) |
| 69 |
} |
| 70 |
|
| 71 |
func TestValidateConfig_ValidZero(t *testing.T) { |
| 72 |
cfg := &Config{} |
| 73 |
assert.NoError(t, cfg.Validate()) |
| 74 |
} |