Add KV store providers (dynamic configuration only)
Co-authored-by: Jean-Baptiste Doumenjou <jb.doumenjou@gmail.com>
This commit is contained in:
parent
028683666d
commit
9b9f4be6a4
61 changed files with 5825 additions and 70 deletions
63
pkg/config/kv/kv_test.go
Normal file
63
pkg/config/kv/kv_test.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package kv
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDecode(t *testing.T) {
|
||||
pairs := mapToPairs(map[string]string{
|
||||
"traefik/fielda": "bar",
|
||||
"traefik/fieldb": "1",
|
||||
"traefik/fieldc": "true",
|
||||
"traefik/fieldd/0": "one",
|
||||
"traefik/fieldd/1": "two",
|
||||
"traefik/fielde": "",
|
||||
"traefik/fieldf/Test1": "A",
|
||||
"traefik/fieldf/Test2": "B",
|
||||
"traefik/fieldg/0/name": "A",
|
||||
"traefik/fieldg/1/name": "B",
|
||||
})
|
||||
|
||||
element := &sample{}
|
||||
|
||||
err := Decode(pairs, element, "traefik")
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := &sample{
|
||||
FieldA: "bar",
|
||||
FieldB: 1,
|
||||
FieldC: true,
|
||||
FieldD: []string{"one", "two"},
|
||||
FieldE: &struct {
|
||||
Name string
|
||||
}{},
|
||||
FieldF: map[string]string{
|
||||
"Test1": "A",
|
||||
"Test2": "B",
|
||||
},
|
||||
FieldG: []sub{
|
||||
{Name: "A"},
|
||||
{Name: "B"},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, expected, element)
|
||||
}
|
||||
|
||||
type sample struct {
|
||||
FieldA string
|
||||
FieldB int
|
||||
FieldC bool
|
||||
FieldD []string
|
||||
FieldE *struct {
|
||||
Name string
|
||||
} `label:"allowEmpty"`
|
||||
FieldF map[string]string
|
||||
FieldG []sub
|
||||
}
|
||||
|
||||
type sub struct {
|
||||
Name string
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue