mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2026-04-22 22:57:04 +08:00
config: refactored confmap koanf provider
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
@@ -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",
|
||||
},
|
||||
}))
|
||||
})
|
||||
Reference in New Issue
Block a user