12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- package configsource
15
+ package configprovider
16
16
17
17
import (
18
18
"context"
19
19
"errors"
20
- "fmt"
21
20
"os"
22
21
"path"
23
22
"testing"
@@ -26,6 +25,7 @@ import (
26
25
"github.com/stretchr/testify/require"
27
26
"go.opentelemetry.io/collector/component"
28
27
"go.opentelemetry.io/collector/config"
28
+ "go.opentelemetry.io/collector/config/experimental/configsource"
29
29
"go.uber.org/zap"
30
30
)
31
31
@@ -81,7 +81,7 @@ func TestConfigSourceManager_NewManager(t *testing.T) {
81
81
82
82
func TestConfigSourceManager_Simple (t * testing.T ) {
83
83
ctx := context .Background ()
84
- manager := newManager (map [string ]ConfigSource {
84
+ manager := newManager (map [string ]configsource. ConfigSource {
85
85
"tstcfgsrc" : & testConfigSource {
86
86
ValueMap : map [string ]valueEntry {
87
87
"test_selector" : {Value : "test_value" },
@@ -119,7 +119,7 @@ func TestConfigSourceManager_Simple(t *testing.T) {
119
119
manager .WaitForWatcher ()
120
120
assert .NoError (t , manager .Close (ctx ))
121
121
<- doneCh
122
- assert .ErrorIs (t , errWatcher , ErrSessionClosed )
122
+ assert .ErrorIs (t , errWatcher , configsource . ErrSessionClosed )
123
123
}
124
124
125
125
func TestConfigSourceManager_ResolveRemoveConfigSourceSection (t * testing.T ) {
@@ -132,7 +132,7 @@ func TestConfigSourceManager_ResolveRemoveConfigSourceSection(t *testing.T) {
132
132
},
133
133
}
134
134
135
- manager := newManager (map [string ]ConfigSource {
135
+ manager := newManager (map [string ]configsource. ConfigSource {
136
136
"tstcfgsrc" : & testConfigSource {},
137
137
})
138
138
@@ -150,15 +150,15 @@ func TestConfigSourceManager_ResolveErrors(t *testing.T) {
150
150
151
151
tests := []struct {
152
152
config map [string ]interface {}
153
- configSourceMap map [string ]ConfigSource
153
+ configSourceMap map [string ]configsource. ConfigSource
154
154
name string
155
155
}{
156
156
{
157
157
name : "incorrect_cfgsrc_ref" ,
158
158
config : map [string ]interface {}{
159
159
"cfgsrc" : "$tstcfgsrc:selector?{invalid}" ,
160
160
},
161
- configSourceMap : map [string ]ConfigSource {
161
+ configSourceMap : map [string ]configsource. ConfigSource {
162
162
"tstcfgsrc" : & testConfigSource {},
163
163
},
164
164
},
@@ -167,7 +167,7 @@ func TestConfigSourceManager_ResolveErrors(t *testing.T) {
167
167
config : map [string ]interface {}{
168
168
"cfgsrc" : "$tstcfgsrc:selector" ,
169
169
},
170
- configSourceMap : map [string ]ConfigSource {
170
+ configSourceMap : map [string ]configsource. ConfigSource {
171
171
"tstcfgsrc" : & testConfigSource {ErrOnNewSession : testErr },
172
172
},
173
173
},
@@ -176,7 +176,7 @@ func TestConfigSourceManager_ResolveErrors(t *testing.T) {
176
176
config : map [string ]interface {}{
177
177
"cfgsrc" : "$tstcfgsrc:selector" ,
178
178
},
179
- configSourceMap : map [string ]ConfigSource {
179
+ configSourceMap : map [string ]configsource. ConfigSource {
180
180
"tstcfgsrc" : & testConfigSource {ErrOnRetrieve : testErr },
181
181
},
182
182
},
@@ -185,7 +185,7 @@ func TestConfigSourceManager_ResolveErrors(t *testing.T) {
185
185
config : map [string ]interface {}{
186
186
"cfgsrc" : "$tstcfgsrc:selector" ,
187
187
},
188
- configSourceMap : map [string ]ConfigSource {
188
+ configSourceMap : map [string ]configsource. ConfigSource {
189
189
"tstcfgsrc" : & testConfigSource {
190
190
ErrOnRetrieveEnd : testErr ,
191
191
ValueMap : map [string ]valueEntry {
@@ -209,7 +209,7 @@ func TestConfigSourceManager_ResolveErrors(t *testing.T) {
209
209
210
210
func TestConfigSourceManager_ArraysAndMaps (t * testing.T ) {
211
211
ctx := context .Background ()
212
- manager := newManager (map [string ]ConfigSource {
212
+ manager := newManager (map [string ]configsource. ConfigSource {
213
213
"tstcfgsrc" : & testConfigSource {
214
214
ValueMap : map [string ]valueEntry {
215
215
"elem0" : {Value : "elem0_value" },
@@ -268,7 +268,7 @@ func TestConfigSourceManager_ParamsHandling(t *testing.T) {
268
268
return nil
269
269
}
270
270
271
- manager := newManager (map [string ]ConfigSource {
271
+ manager := newManager (map [string ]configsource. ConfigSource {
272
272
"tstcfgsrc" : & tstCfgSrc ,
273
273
})
274
274
@@ -292,7 +292,7 @@ func TestConfigSourceManager_WatchForUpdate(t *testing.T) {
292
292
ctx := context .Background ()
293
293
watchForUpdateCh := make (chan error , 1 )
294
294
295
- manager := newManager (map [string ]ConfigSource {
295
+ manager := newManager (map [string ]configsource. ConfigSource {
296
296
"tstcfgsrc" : & testConfigSource {
297
297
ValueMap : map [string ]valueEntry {
298
298
"test_selector" : {
@@ -323,10 +323,10 @@ func TestConfigSourceManager_WatchForUpdate(t *testing.T) {
323
323
}()
324
324
325
325
manager .WaitForWatcher ()
326
- watchForUpdateCh <- ErrValueUpdated
326
+ watchForUpdateCh <- configsource . ErrValueUpdated
327
327
328
328
<- doneCh
329
- assert .ErrorIs (t , errWatcher , ErrValueUpdated )
329
+ assert .ErrorIs (t , errWatcher , configsource . ErrValueUpdated )
330
330
assert .NoError (t , manager .Close (ctx ))
331
331
}
332
332
@@ -341,11 +341,11 @@ func TestConfigSourceManager_MultipleWatchForUpdate(t *testing.T) {
341
341
case errFromWatchForUpdate := <- watchForUpdateCh :
342
342
return errFromWatchForUpdate
343
343
case <- watchDoneCh :
344
- return ErrSessionClosed
344
+ return configsource . ErrSessionClosed
345
345
}
346
346
}
347
347
348
- manager := newManager (map [string ]ConfigSource {
348
+ manager := newManager (map [string ]configsource. ConfigSource {
349
349
"tstcfgsrc" : & testConfigSource {
350
350
ValueMap : map [string ]valueEntry {
351
351
"test_selector" : {
@@ -379,11 +379,11 @@ func TestConfigSourceManager_MultipleWatchForUpdate(t *testing.T) {
379
379
manager .WaitForWatcher ()
380
380
381
381
for i := 0 ; i < watchForUpdateChSize ; i ++ {
382
- watchForUpdateCh <- ErrValueUpdated
382
+ watchForUpdateCh <- configsource . ErrValueUpdated
383
383
}
384
384
385
385
<- doneCh
386
- assert .ErrorIs (t , errWatcher , ErrValueUpdated )
386
+ assert .ErrorIs (t , errWatcher , configsource . ErrValueUpdated )
387
387
close (watchForUpdateCh )
388
388
assert .NoError (t , manager .Close (ctx ))
389
389
}
@@ -409,7 +409,7 @@ func TestConfigSourceManager_EnvVarHandling(t *testing.T) {
409
409
return nil
410
410
}
411
411
412
- manager := newManager (map [string ]ConfigSource {
412
+ manager := newManager (map [string ]configsource. ConfigSource {
413
413
"tstcfgsrc" : & tstCfgSrc ,
414
414
})
415
415
@@ -431,7 +431,7 @@ func TestConfigSourceManager_EnvVarHandling(t *testing.T) {
431
431
432
432
func TestManager_expandString (t * testing.T ) {
433
433
ctx := context .Background ()
434
- manager := newManager (map [string ]ConfigSource {
434
+ manager := newManager (map [string ]configsource. ConfigSource {
435
435
"tstcfgsrc" : & testConfigSource {
436
436
ValueMap : map [string ]valueEntry {
437
437
"str_key" : {Value : "test_value" },
@@ -621,68 +621,3 @@ func Test_parseCfgSrc(t *testing.T) {
621
621
})
622
622
}
623
623
}
624
-
625
- // testConfigSource a ConfigSource to be used in tests.
626
- type testConfigSource struct {
627
- ValueMap map [string ]valueEntry
628
-
629
- ErrOnNewSession error
630
- ErrOnRetrieve error
631
- ErrOnRetrieveEnd error
632
- ErrOnClose error
633
-
634
- OnRetrieve func (ctx context.Context , selector string , params interface {}) error
635
- }
636
-
637
- type valueEntry struct {
638
- Value interface {}
639
- WatchForUpdateFn func () error
640
- }
641
-
642
- var _ (ConfigSource ) = (* testConfigSource )(nil )
643
- var _ (Session ) = (* testConfigSource )(nil )
644
-
645
- func (t * testConfigSource ) NewSession (context.Context ) (Session , error ) {
646
- if t .ErrOnNewSession != nil {
647
- return nil , t .ErrOnNewSession
648
- }
649
- return t , nil
650
- }
651
-
652
- func (t * testConfigSource ) Retrieve (ctx context.Context , selector string , params interface {}) (Retrieved , error ) {
653
- if t .OnRetrieve != nil {
654
- if err := t .OnRetrieve (ctx , selector , params ); err != nil {
655
- return nil , err
656
- }
657
- }
658
-
659
- if t .ErrOnRetrieve != nil {
660
- return nil , t .ErrOnRetrieve
661
- }
662
-
663
- entry , ok := t .ValueMap [selector ]
664
- if ! ok {
665
- return nil , fmt .Errorf ("no value for selector %q" , selector )
666
- }
667
-
668
- watchForUpdateFn := func () error {
669
- return ErrWatcherNotSupported
670
- }
671
-
672
- if entry .WatchForUpdateFn != nil {
673
- watchForUpdateFn = entry .WatchForUpdateFn
674
- }
675
-
676
- return & retrieved {
677
- value : entry .Value ,
678
- watchForUpdateFn : watchForUpdateFn ,
679
- }, nil
680
- }
681
-
682
- func (t * testConfigSource ) RetrieveEnd (context.Context ) error {
683
- return t .ErrOnRetrieveEnd
684
- }
685
-
686
- func (t * testConfigSource ) Close (context.Context ) error {
687
- return t .ErrOnClose
688
- }
0 commit comments