@@ -9,15 +9,18 @@ import (
9
9
"testing"
10
10
11
11
"github.com/stretchr/testify/assert"
12
+ "github.com/stretchr/testify/require"
12
13
13
14
"go.opentelemetry.io/collector/component"
15
+ "go.opentelemetry.io/collector/featuregate"
14
16
"go.opentelemetry.io/collector/pipeline"
17
+ "go.opentelemetry.io/collector/pipeline/pipelineprofiles"
15
18
)
16
19
17
20
func TestConfigValidate (t * testing.T ) {
18
21
var testCases = []struct {
19
22
name string // test case name (also file name containing config yaml)
20
- cfgFn func () Config
23
+ cfgFn func (* testing. T ) Config
21
24
expected error
22
25
}{
23
26
{
@@ -27,8 +30,8 @@ func TestConfigValidate(t *testing.T) {
27
30
},
28
31
{
29
32
name : "duplicate-processor-reference" ,
30
- cfgFn : func () Config {
31
- cfg := generateConfig ()
33
+ cfgFn : func (* testing. T ) Config {
34
+ cfg := generateConfig (t )
32
35
pipe := cfg [pipeline .NewID (pipeline .SignalTraces )]
33
36
pipe .Processors = append (pipe .Processors , pipe .Processors ... )
34
37
return cfg
@@ -37,33 +40,33 @@ func TestConfigValidate(t *testing.T) {
37
40
},
38
41
{
39
42
name : "missing-pipeline-receivers" ,
40
- cfgFn : func () Config {
41
- cfg := generateConfig ()
43
+ cfgFn : func (* testing. T ) Config {
44
+ cfg := generateConfig (t )
42
45
cfg [pipeline .NewID (pipeline .SignalTraces )].Receivers = nil
43
46
return cfg
44
47
},
45
48
expected : fmt .Errorf (`pipeline "traces": %w` , errMissingServicePipelineReceivers ),
46
49
},
47
50
{
48
51
name : "missing-pipeline-exporters" ,
49
- cfgFn : func () Config {
50
- cfg := generateConfig ()
52
+ cfgFn : func (* testing. T ) Config {
53
+ cfg := generateConfig (t )
51
54
cfg [pipeline .NewID (pipeline .SignalTraces )].Exporters = nil
52
55
return cfg
53
56
},
54
57
expected : fmt .Errorf (`pipeline "traces": %w` , errMissingServicePipelineExporters ),
55
58
},
56
59
{
57
60
name : "missing-pipelines" ,
58
- cfgFn : func () Config {
61
+ cfgFn : func (* testing. T ) Config {
59
62
return nil
60
63
},
61
64
expected : errMissingServicePipelines ,
62
65
},
63
66
{
64
67
name : "invalid-service-pipeline-type" ,
65
- cfgFn : func () Config {
66
- cfg := generateConfig ()
68
+ cfgFn : func (* testing. T ) Config {
69
+ cfg := generateConfig (t )
67
70
cfg [pipeline .MustNewID ("wrongtype" )] = & PipelineConfig {
68
71
Receivers : []component.ID {component .MustNewID ("nop" )},
69
72
Processors : []component.ID {component .MustNewID ("nop" )},
@@ -73,17 +76,50 @@ func TestConfigValidate(t *testing.T) {
73
76
},
74
77
expected : errors .New (`pipeline "wrongtype": unknown signal "wrongtype"` ),
75
78
},
79
+ {
80
+ name : "disabled-featuregate-profiles" ,
81
+ cfgFn : func (* testing.T ) Config {
82
+ cfg := generateConfig (t )
83
+ cfg [pipeline .NewID (pipelineprofiles .SignalProfiles )] = & PipelineConfig {
84
+ Receivers : []component.ID {component .MustNewID ("nop" )},
85
+ Processors : []component.ID {component .MustNewID ("nop" )},
86
+ Exporters : []component.ID {component .MustNewID ("nop" )},
87
+ }
88
+ return cfg
89
+ },
90
+ expected : errors .New (`pipeline "profiles": profiling signal support is at alpha level, gated under the "service.profilesSupport" feature gate` ),
91
+ },
92
+ {
93
+ name : "enabled-featuregate-profiles" ,
94
+ cfgFn : func (t * testing.T ) Config {
95
+ require .NoError (t , featuregate .GlobalRegistry ().Set (serviceProfileSupportGateID , true ))
96
+
97
+ cfg := generateConfig (t )
98
+ cfg [pipeline .NewID (pipelineprofiles .SignalProfiles )] = & PipelineConfig {
99
+ Receivers : []component.ID {component .MustNewID ("nop" )},
100
+ Processors : []component.ID {component .MustNewID ("nop" )},
101
+ Exporters : []component.ID {component .MustNewID ("nop" )},
102
+ }
103
+ return cfg
104
+ },
105
+ expected : nil ,
106
+ },
76
107
}
77
108
78
109
for _ , tt := range testCases {
79
110
t .Run (tt .name , func (t * testing.T ) {
80
- cfg := tt .cfgFn ()
111
+ cfg := tt .cfgFn (t )
81
112
assert .Equal (t , tt .expected , cfg .Validate ())
113
+
114
+ // Clean up the profiles support gate, which may have been enabled in `cfgFn`.
115
+ require .NoError (t , featuregate .GlobalRegistry ().Set (serviceProfileSupportGateID , false ))
82
116
})
83
117
}
84
118
}
85
119
86
- func generateConfig () Config {
120
+ func generateConfig (t * testing.T ) Config {
121
+ t .Helper ()
122
+
87
123
return map [pipeline.ID ]* PipelineConfig {
88
124
pipeline .NewID (pipeline .SignalTraces ): {
89
125
Receivers : []component.ID {component .MustNewID ("nop" )},
0 commit comments