|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package attribute |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | + |
| 11 | + "go.opentelemetry.io/collector/component" |
| 12 | + "go.opentelemetry.io/collector/pipeline" |
| 13 | + "go.opentelemetry.io/collector/pipeline/pipelineprofiles" |
| 14 | +) |
| 15 | + |
| 16 | +var ( |
| 17 | + signals = []pipeline.Signal{ |
| 18 | + pipeline.SignalTraces, |
| 19 | + pipeline.SignalMetrics, |
| 20 | + pipeline.SignalLogs, |
| 21 | + pipelineprofiles.SignalProfiles, |
| 22 | + } |
| 23 | + |
| 24 | + cIDs = []component.ID{ |
| 25 | + component.MustNewID("foo"), |
| 26 | + component.MustNewID("foo2"), |
| 27 | + component.MustNewID("bar"), |
| 28 | + } |
| 29 | + |
| 30 | + pIDs = []pipeline.ID{ |
| 31 | + pipeline.MustNewID("traces"), |
| 32 | + pipeline.MustNewIDWithName("traces", "2"), |
| 33 | + pipeline.MustNewID("metrics"), |
| 34 | + pipeline.MustNewIDWithName("metrics", "2"), |
| 35 | + pipeline.MustNewID("logs"), |
| 36 | + pipeline.MustNewIDWithName("logs", "2"), |
| 37 | + pipeline.MustNewID("profiles"), |
| 38 | + pipeline.MustNewIDWithName("profiles", "2"), |
| 39 | + } |
| 40 | +) |
| 41 | + |
| 42 | +func TestAttributes(t *testing.T) { |
| 43 | + // The sets are created independently but should be exactly equivalent. |
| 44 | + // We will ensure that corresponding elements are equal and that |
| 45 | + // non-corresponding elements are not equal. |
| 46 | + setI, setJ := createExampleSets(), createExampleSets() |
| 47 | + for i, ei := range setI { |
| 48 | + for j, ej := range setJ { |
| 49 | + if i == j { |
| 50 | + require.Equal(t, ei.ID(), ej.ID()) |
| 51 | + require.True(t, ei.Attributes().Equals(ej.Attributes())) |
| 52 | + } else { |
| 53 | + require.NotEqual(t, ei.ID(), ej.ID()) |
| 54 | + require.False(t, ei.Attributes().Equals(ej.Attributes())) |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +func createExampleSets() []*Attributes { |
| 61 | + sets := []*Attributes{} |
| 62 | + |
| 63 | + // Receiver examples. |
| 64 | + for _, sig := range signals { |
| 65 | + for _, id := range cIDs { |
| 66 | + sets = append(sets, Receiver(sig, id)) |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + // Processor examples. |
| 71 | + for _, pID := range pIDs { |
| 72 | + for _, cID := range cIDs { |
| 73 | + sets = append(sets, Processor(pID, cID)) |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + // Exporter examples. |
| 78 | + for _, sig := range signals { |
| 79 | + for _, id := range cIDs { |
| 80 | + sets = append(sets, Exporter(sig, id)) |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + // Connector examples. |
| 85 | + for _, exprSig := range signals { |
| 86 | + for _, rcvrSig := range signals { |
| 87 | + for _, id := range cIDs { |
| 88 | + sets = append(sets, Connector(exprSig, rcvrSig, id)) |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + // Capabilities examples. |
| 94 | + for _, pID := range pIDs { |
| 95 | + sets = append(sets, Capabilities(pID)) |
| 96 | + } |
| 97 | + |
| 98 | + // Fanout examples. |
| 99 | + for _, pID := range pIDs { |
| 100 | + sets = append(sets, Fanout(pID)) |
| 101 | + } |
| 102 | + |
| 103 | + return sets |
| 104 | +} |
0 commit comments