Skip to content

Commit 32f0492

Browse files
add coverage
Signed-off-by: Thomas Poignant <[email protected]>
1 parent 7cda738 commit 32f0492

File tree

1 file changed

+96
-4
lines changed

1 file changed

+96
-4
lines changed

cmd/relayproxy/service/gofeatureflag_test.go

+96-4
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ func Test_initRetriever(t *testing.T) {
240240
})
241241
}
242242
}
243-
244243
func Test_initRetrievers(t *testing.T) {
245244
tests := []struct {
246245
name string
@@ -295,9 +294,6 @@ func Test_initRetrievers(t *testing.T) {
295294
Kind: "unknown",
296295
},
297296
},
298-
retriever: &config.RetrieverConf{
299-
Kind: "unknown",
300-
},
301297
},
302298
{
303299
name: "only retriever",
@@ -349,6 +345,102 @@ func Test_initRetrievers(t *testing.T) {
349345
}
350346
}
351347

348+
func Test_initExporters(t *testing.T) {
349+
tests := []struct {
350+
name string
351+
exporters *[]config.ExporterConf
352+
exporter *config.ExporterConf
353+
wantErr assert.ErrorAssertionFunc
354+
}{
355+
{
356+
name: "both exporter and exporters",
357+
wantErr: assert.NoError,
358+
exporter: &config.ExporterConf{
359+
Kind: "webhook",
360+
EndpointURL: "https://gofeatureflag.org/webhook-example",
361+
Secret: "1234",
362+
},
363+
exporters: &[]config.ExporterConf{
364+
{
365+
Kind: "webhook",
366+
EndpointURL: "https://gofeatureflag.org/webhook-example",
367+
Secret: "1234",
368+
},
369+
},
370+
},
371+
{
372+
name: "exporter only",
373+
wantErr: assert.NoError,
374+
exporter: &config.ExporterConf{
375+
Kind: "webhook",
376+
EndpointURL: "https://gofeatureflag.org/webhook-example",
377+
Secret: "1234",
378+
},
379+
},
380+
{
381+
name: "exporters only",
382+
wantErr: assert.NoError,
383+
exporters: &[]config.ExporterConf{
384+
{
385+
Kind: "webhook",
386+
EndpointURL: "https://gofeatureflag.org/webhook-example",
387+
Secret: "1234",
388+
},
389+
},
390+
},
391+
{
392+
name: "invalid exporter",
393+
wantErr: assert.Error,
394+
exporter: &config.ExporterConf{
395+
Kind: "invalid",
396+
},
397+
exporters: &[]config.ExporterConf{
398+
{
399+
Kind: "webhook",
400+
EndpointURL: "https://gofeatureflag.org/webhook-example",
401+
Secret: "1234",
402+
},
403+
},
404+
},
405+
{
406+
name: "invalid exporters",
407+
wantErr: assert.Error,
408+
exporter: &config.ExporterConf{
409+
410+
Kind: "webhook",
411+
EndpointURL: "https://gofeatureflag.org/webhook-example",
412+
Secret: "1234",
413+
},
414+
exporters: &[]config.ExporterConf{
415+
{
416+
Kind: "invalid",
417+
},
418+
},
419+
},
420+
}
421+
422+
for _, tt := range tests {
423+
t.Run(tt.name, func(t *testing.T) {
424+
proxyConf := config.Config{
425+
Exporters: tt.exporters,
426+
Exporter: tt.exporter,
427+
}
428+
r, err := initDataExporters(&proxyConf)
429+
tt.wantErr(t, err)
430+
if r != nil {
431+
nbExp := 0
432+
if tt.exporters != nil {
433+
nbExp += len(*tt.exporters)
434+
}
435+
if tt.exporter != nil {
436+
nbExp++
437+
}
438+
assert.Len(t, r, nbExp)
439+
}
440+
})
441+
}
442+
}
443+
352444
func Test_initExporter(t *testing.T) {
353445
tests := []struct {
354446
name string

0 commit comments

Comments
 (0)