config: refactored confmap koanf provider

Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
Steffen Vogel
2022-09-24 12:05:36 +02:00
parent 631197e104
commit 11ff735f58
3 changed files with 148 additions and 50 deletions
+73
View File
@@ -0,0 +1,73 @@
package config_test
import (
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pion/ice/v2"
"github.com/stv0g/cunicu/pkg/config"
icex "github.com/stv0g/cunicu/pkg/ice"
)
var _ = It("map", func() {
s := config.Settings{
WatchInterval: 5 * time.Second,
Interfaces: map[string]config.InterfaceSettings{
"wg0": {
EndpointDisc: config.EndpointDiscoverySettings{
ICE: config.ICESettings{
NetworkTypes: []icex.NetworkType{
{NetworkType: ice.NetworkTypeTCP4},
{NetworkType: ice.NetworkTypeTCP6},
},
},
},
PeerDisc: config.PeerDiscoverySettings{
Hostname: "test",
},
},
},
DefaultInterfaceSettings: config.InterfaceSettings{
PeerDisc: config.PeerDiscoverySettings{
Hostname: "test2",
},
Hooks: []config.HookSetting{
&config.ExecHookSetting{
BaseHookSetting: config.BaseHookSetting{
Type: "exec",
},
Command: "dummy",
Env: map[string]string{
"ENV1": "value1",
},
},
},
},
}
m := config.Map(s, "koanf")
Expect(m).To(Equal(map[string]any{
"watch_interval": 5 * time.Second,
"interfaces": map[string]any{
"wg0": map[string]any{
"epdisc": map[string]any{
"ice": map[string]any{
"network_types": []icex.NetworkType{
{NetworkType: ice.NetworkTypeTCP4},
{NetworkType: ice.NetworkTypeTCP6},
},
},
},
"pdisc": map[string]any{
"hostname": "test",
},
},
},
"hooks": s.DefaultInterfaceSettings.Hooks,
"pdisc": map[string]any{
"hostname": "test2",
},
}))
})