|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package coldstartprocessor // import "github.com/open-telemetry/opentelemetry-lambda/collector/processor/coldstartprocessor" |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/stretchr/testify/require" |
| 22 | + "go.opentelemetry.io/collector/consumer/consumertest" |
| 23 | + "go.opentelemetry.io/collector/processor/processortest" |
| 24 | +) |
| 25 | + |
| 26 | +func TestNewFactory(t *testing.T) { |
| 27 | + testCases := []struct { |
| 28 | + desc string |
| 29 | + testFunc func(*testing.T) |
| 30 | + }{ |
| 31 | + { |
| 32 | + desc: "creates a new factory with correct type", |
| 33 | + testFunc: func(t *testing.T) { |
| 34 | + factory := NewFactory() |
| 35 | + require.EqualValues(t, typeStr, factory.Type()) |
| 36 | + }, |
| 37 | + }, |
| 38 | + { |
| 39 | + desc: "creates a new factory and CreateTracesProcessor returns no error", |
| 40 | + testFunc: func(t *testing.T) { |
| 41 | + factory := NewFactory() |
| 42 | + cfg := factory.CreateDefaultConfig() |
| 43 | + _, err := factory.CreateTracesProcessor( |
| 44 | + context.Background(), |
| 45 | + processortest.NewNopCreateSettings(), |
| 46 | + cfg, |
| 47 | + consumertest.NewNop(), |
| 48 | + ) |
| 49 | + require.NoError(t, err) |
| 50 | + }, |
| 51 | + }, |
| 52 | + { |
| 53 | + desc: "creates a new factory and CreateTracesProcessor returns error with incorrect config", |
| 54 | + testFunc: func(t *testing.T) { |
| 55 | + factory := NewFactory() |
| 56 | + _, err := factory.CreateTracesProcessor( |
| 57 | + context.Background(), |
| 58 | + processortest.NewNopCreateSettings(), |
| 59 | + nil, |
| 60 | + consumertest.NewNop(), |
| 61 | + ) |
| 62 | + require.ErrorIs(t, err, errConfigNotColdstart) |
| 63 | + }, |
| 64 | + }, |
| 65 | + } |
| 66 | + |
| 67 | + for _, tc := range testCases { |
| 68 | + t.Run(tc.desc, tc.testFunc) |
| 69 | + } |
| 70 | +} |
0 commit comments