Debian Codegraph @

component/component_test.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package component
5
6 import (
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 )
11
12 func TestKindString(t *testing.T) {
13 assert.Empty(t, Kind{}.String())
14 assert.Equal(t, "Receiver", KindReceiver.String())
15 assert.Equal(t, "Processor", KindProcessor.String())
16 assert.Equal(t, "Exporter", KindExporter.String())
17 assert.Equal(t, "Extension", KindExtension.String())
18 assert.Equal(t, "Connector", KindConnector.String())
19 }
20
21 func TestStabilityLevelUnmarshal(t *testing.T) {
22 tests := []struct {
23 input string
24 output StabilityLevel
25 expectedErr string
26 }{
27 {
28 input: "Undefined",
29 output: StabilityLevelUndefined,
30 },
31 {
32 input: "UnmaintaineD",
33 output: StabilityLevelUnmaintained,
34 },
35 {
36 input: "DepreCated",
37 output: StabilityLevelDeprecated,
38 },
39 {
40 input: "Development",
41 output: StabilityLevelDevelopment,
42 },
43 {
44 input: "alpha",
45 output: StabilityLevelAlpha,
46 },
47 {
48 input: "BETA",
49 output: StabilityLevelBeta,
50 },
51 {
52 input: "sTABLe",
53 output: StabilityLevelStable,
54 },
55 {
56 input: "notfound",
57 expectedErr: "unsupported stability level: \"notfound\"",
58 },
59 }
60 for _, test := range tests {
61 t.Run(test.input, func(t *testing.T) {
62 var sl StabilityLevel
63 err := sl.UnmarshalText([]byte(test.input))
64 if test.expectedErr != "" {
65 assert.EqualError(t, err, test.expectedErr)
66 } else {
67 assert.Equal(t, test.output, sl)
68 }
69 })
70 }
71 }
72
73 func TestStabilityLevelString(t *testing.T) {
74 assert.Equal(t, "Undefined", StabilityLevelUndefined.String())
75 assert.Equal(t, "Unmaintained", StabilityLevelUnmaintained.String())
76 assert.Equal(t, "Deprecated", StabilityLevelDeprecated.String())
77 assert.Equal(t, "Development", StabilityLevelDevelopment.String())
78 assert.Equal(t, "Alpha", StabilityLevelAlpha.String())
79 assert.Equal(t, "Beta", StabilityLevelBeta.String())
80 assert.Equal(t, "Stable", StabilityLevelStable.String())
81 assert.Empty(t, StabilityLevel(100).String())
82 }
83
84 func TestStabilityLevelLogMessage(t *testing.T) {
85 assert.Equal(t, "Stability level of component is undefined", StabilityLevelUndefined.LogMessage())
86 assert.Equal(t, "Unmaintained component. Actively looking for contributors. Component will become deprecated after 3 months of remaining unmaintained.", StabilityLevelUnmaintained.LogMessage())
87 assert.Equal(t, "Deprecated component. Will be removed in future releases.", StabilityLevelDeprecated.LogMessage())
88 assert.Equal(t, "Development component. May change in the future.", StabilityLevelDevelopment.LogMessage())
89 assert.Equal(t, "Alpha component. May change in the future.", StabilityLevelAlpha.LogMessage())
90 assert.Equal(t, "Beta component. May change in the future.", StabilityLevelBeta.LogMessage())
91 assert.Equal(t, "Stable component.", StabilityLevelStable.LogMessage())
92 assert.Equal(t, "Stability level of component is undefined", StabilityLevel(100).LogMessage())
93 }