1
1
package flagd
2
2
3
3
import (
4
+ "testing"
5
+
6
+ "github.com/open-feature/flagd/core/pkg/sync"
4
7
"github.com/open-feature/go-sdk-contrib/providers/flagd/internal/cache"
5
8
"github.com/open-feature/go-sdk-contrib/providers/flagd/internal/mock"
9
+ process "github.com/open-feature/go-sdk-contrib/providers/flagd/pkg/service/in_process"
6
10
of "github.com/open-feature/go-sdk/openfeature"
7
11
"go.uber.org/mock/gomock"
8
- "testing"
9
12
)
10
13
11
14
func TestNewProvider (t * testing.T ) {
15
+ customSyncProvider := process .NewDoNothingCustomSyncProvider ()
16
+
12
17
tests := []struct {
13
- name string
14
- expectedResolver ResolverType
15
- expectPort uint16
16
- expectHost string
17
- expectTargetUri string
18
- expectCacheType cache.Type
19
- expectCertPath string
20
- expectMaxRetries int
21
- expectCacheSize int
22
- expectOtelIntercept bool
23
- expectSocketPath string
24
- expectTlsEnabled bool
25
- options []ProviderOption
18
+ name string
19
+ expectedResolver ResolverType
20
+ expectPort uint16
21
+ expectHost string
22
+ expectTargetUri string
23
+ expectCacheType cache.Type
24
+ expectCertPath string
25
+ expectMaxRetries int
26
+ expectCacheSize int
27
+ expectOtelIntercept bool
28
+ expectSocketPath string
29
+ expectTlsEnabled bool
30
+ expectCustomSyncProvider sync.ISync
31
+ expectCustomSyncProviderUri string
32
+ options []ProviderOption
26
33
}{
27
34
{
28
- name : "default construction" ,
29
- expectedResolver : rpc ,
30
- expectPort : defaultRpcPort ,
31
- expectHost : defaultHost ,
32
- expectTargetUri : "" ,
33
- expectCacheType : defaultCache ,
34
- expectCertPath : "" ,
35
- expectMaxRetries : defaultMaxEventStreamRetries ,
36
- expectCacheSize : defaultMaxCacheSize ,
37
- expectOtelIntercept : false ,
38
- expectSocketPath : "" ,
39
- expectTlsEnabled : false ,
35
+ name : "default construction" ,
36
+ expectedResolver : rpc ,
37
+ expectPort : defaultRpcPort ,
38
+ expectHost : defaultHost ,
39
+ expectTargetUri : "" ,
40
+ expectCacheType : defaultCache ,
41
+ expectCertPath : "" ,
42
+ expectMaxRetries : defaultMaxEventStreamRetries ,
43
+ expectCacheSize : defaultMaxCacheSize ,
44
+ expectOtelIntercept : false ,
45
+ expectSocketPath : "" ,
46
+ expectTlsEnabled : false ,
47
+ expectCustomSyncProvider : nil ,
48
+ expectCustomSyncProviderUri : "" ,
40
49
},
41
50
{
42
- name : "with options" ,
43
- expectedResolver : inProcess ,
44
- expectPort : 9090 ,
45
- expectHost : "myHost" ,
46
- expectTargetUri : "" ,
47
- expectCacheType : cache .LRUValue ,
48
- expectCertPath : "/path" ,
49
- expectMaxRetries : 2 ,
50
- expectCacheSize : 2500 ,
51
- expectOtelIntercept : true ,
52
- expectSocketPath : "/socket" ,
53
- expectTlsEnabled : true ,
51
+ name : "with options" ,
52
+ expectedResolver : inProcess ,
53
+ expectPort : 9090 ,
54
+ expectHost : "myHost" ,
55
+ expectTargetUri : "" ,
56
+ expectCacheType : cache .LRUValue ,
57
+ expectCertPath : "/path" ,
58
+ expectMaxRetries : 2 ,
59
+ expectCacheSize : 2500 ,
60
+ expectOtelIntercept : true ,
61
+ expectSocketPath : "/socket" ,
62
+ expectTlsEnabled : true ,
63
+ expectCustomSyncProvider : nil ,
64
+ expectCustomSyncProviderUri : "" ,
54
65
options : []ProviderOption {
55
66
WithInProcessResolver (),
56
67
WithSocketPath ("/socket" ),
@@ -63,57 +74,103 @@ func TestNewProvider(t *testing.T) {
63
74
},
64
75
},
65
76
{
66
- name : "default port handling with in-process resolver" ,
67
- expectedResolver : inProcess ,
68
- expectPort : defaultInProcessPort ,
69
- expectHost : defaultHost ,
70
- expectCacheType : defaultCache ,
71
- expectTargetUri : "" ,
72
- expectCertPath : "" ,
73
- expectMaxRetries : defaultMaxEventStreamRetries ,
74
- expectCacheSize : defaultMaxCacheSize ,
75
- expectOtelIntercept : false ,
76
- expectSocketPath : "" ,
77
- expectTlsEnabled : false ,
77
+ name : "default port handling with in-process resolver" ,
78
+ expectedResolver : inProcess ,
79
+ expectPort : defaultInProcessPort ,
80
+ expectHost : defaultHost ,
81
+ expectCacheType : defaultCache ,
82
+ expectTargetUri : "" ,
83
+ expectCertPath : "" ,
84
+ expectMaxRetries : defaultMaxEventStreamRetries ,
85
+ expectCacheSize : defaultMaxCacheSize ,
86
+ expectOtelIntercept : false ,
87
+ expectSocketPath : "" ,
88
+ expectTlsEnabled : false ,
89
+ expectCustomSyncProvider : nil ,
90
+ expectCustomSyncProviderUri : "" ,
78
91
options : []ProviderOption {
79
92
WithInProcessResolver (),
80
93
},
81
94
},
82
95
{
83
- name : "default port handling with in-process resolver" ,
84
- expectedResolver : rpc ,
85
- expectPort : defaultRpcPort ,
86
- expectHost : defaultHost ,
87
- expectTargetUri : "" ,
88
- expectCacheType : defaultCache ,
89
- expectCertPath : "" ,
90
- expectMaxRetries : defaultMaxEventStreamRetries ,
91
- expectCacheSize : defaultMaxCacheSize ,
92
- expectOtelIntercept : false ,
93
- expectSocketPath : "" ,
94
- expectTlsEnabled : false ,
96
+ name : "default port handling with in-process resolver" ,
97
+ expectedResolver : rpc ,
98
+ expectPort : defaultRpcPort ,
99
+ expectHost : defaultHost ,
100
+ expectTargetUri : "" ,
101
+ expectCacheType : defaultCache ,
102
+ expectCertPath : "" ,
103
+ expectMaxRetries : defaultMaxEventStreamRetries ,
104
+ expectCacheSize : defaultMaxCacheSize ,
105
+ expectOtelIntercept : false ,
106
+ expectSocketPath : "" ,
107
+ expectTlsEnabled : false ,
108
+ expectCustomSyncProvider : nil ,
109
+ expectCustomSyncProviderUri : "" ,
95
110
options : []ProviderOption {
96
111
WithRPCResolver (),
97
112
},
98
113
},
99
114
{
100
- name : "with target uri with in-process resolver" ,
101
- expectedResolver : inProcess ,
102
- expectPort : defaultInProcessPort ,
103
- expectHost : defaultHost ,
104
- expectCacheType : defaultCache ,
105
- expectTargetUri : "envoy://localhost:9211/test.service" ,
106
- expectCertPath : "" ,
107
- expectMaxRetries : defaultMaxEventStreamRetries ,
108
- expectCacheSize : defaultMaxCacheSize ,
109
- expectOtelIntercept : false ,
110
- expectSocketPath : "" ,
111
- expectTlsEnabled : false ,
115
+ name : "with target uri with in-process resolver" ,
116
+ expectedResolver : inProcess ,
117
+ expectPort : defaultInProcessPort ,
118
+ expectHost : defaultHost ,
119
+ expectCacheType : defaultCache ,
120
+ expectTargetUri : "envoy://localhost:9211/test.service" ,
121
+ expectCertPath : "" ,
122
+ expectMaxRetries : defaultMaxEventStreamRetries ,
123
+ expectCacheSize : defaultMaxCacheSize ,
124
+ expectOtelIntercept : false ,
125
+ expectSocketPath : "" ,
126
+ expectTlsEnabled : false ,
127
+ expectCustomSyncProvider : nil ,
128
+ expectCustomSyncProviderUri : "" ,
112
129
options : []ProviderOption {
113
130
WithInProcessResolver (),
114
131
WithTargetUri ("envoy://localhost:9211/test.service" ),
115
132
},
116
133
},
134
+ {
135
+ name : "with custom sync provider and uri with in-process resolver" ,
136
+ expectedResolver : inProcess ,
137
+ expectPort : defaultInProcessPort ,
138
+ expectHost : defaultHost ,
139
+ expectCacheType : defaultCache ,
140
+ expectTargetUri : "" ,
141
+ expectCertPath : "" ,
142
+ expectMaxRetries : defaultMaxEventStreamRetries ,
143
+ expectCacheSize : defaultMaxCacheSize ,
144
+ expectOtelIntercept : false ,
145
+ expectSocketPath : "" ,
146
+ expectTlsEnabled : false ,
147
+ expectCustomSyncProvider : customSyncProvider ,
148
+ expectCustomSyncProviderUri : "testsyncer://custom.uri" ,
149
+ options : []ProviderOption {
150
+ WithInProcessResolver (),
151
+ WithCustomSyncProviderAndUri (customSyncProvider , "testsyncer://custom.uri" ),
152
+ },
153
+ },
154
+ {
155
+ name : "with custom sync provider with in-process resolver" ,
156
+ expectedResolver : inProcess ,
157
+ expectPort : defaultInProcessPort ,
158
+ expectHost : defaultHost ,
159
+ expectCacheType : defaultCache ,
160
+ expectTargetUri : "" ,
161
+ expectCertPath : "" ,
162
+ expectMaxRetries : defaultMaxEventStreamRetries ,
163
+ expectCacheSize : defaultMaxCacheSize ,
164
+ expectOtelIntercept : false ,
165
+ expectSocketPath : "" ,
166
+ expectTlsEnabled : false ,
167
+ expectCustomSyncProvider : customSyncProvider ,
168
+ expectCustomSyncProviderUri : defaultCustomSyncProviderUri ,
169
+ options : []ProviderOption {
170
+ WithInProcessResolver (),
171
+ WithCustomSyncProvider (customSyncProvider ),
172
+ },
173
+ },
117
174
}
118
175
119
176
for _ , test := range tests {
@@ -172,6 +229,16 @@ func TestNewProvider(t *testing.T) {
172
229
test .expectTargetUri , config .TargetUri )
173
230
}
174
231
232
+ if config .CustomSyncProvider != test .expectCustomSyncProvider {
233
+ t .Errorf ("incorrect configuration CustomSyncProvider, expected %v, got %v" ,
234
+ test .expectCustomSyncProvider , config .CustomSyncProvider )
235
+ }
236
+
237
+ if config .CustomSyncProviderUri != test .expectCustomSyncProviderUri {
238
+ t .Errorf ("incorrect configuration CustomSyncProviderUri, expected %v, got %v" ,
239
+ test .expectCustomSyncProviderUri , config .CustomSyncProviderUri )
240
+ }
241
+
175
242
// this line will fail linting if this provider is no longer compatible with the openfeature sdk
176
243
var _ of.FeatureProvider = flagdProvider
177
244
})
0 commit comments