api/internal/app/config_test.go
Peter Kurfer d70ba748f5 Introduce Lifecycle for every endpoint and manage listeners in the renamed Orchestrator
- merge packages to get a more concise layout because plugins are no more and therefore there's not a lot to be exported
- fix test logger
- rework config parsing to be easier and more transparent
- remove unnecessary APIs because dynamic endpoint handling is rather a won't implement
2021-02-10 20:26:45 +00:00

70 lines
1.3 KiB
Go

package app
import (
"reflect"
"testing"
"gitlab.com/inetmock/inetmock/internal/endpoint"
)
func Test_config_ReadConfig(t *testing.T) {
type args struct {
config string
}
tests := []struct {
name string
args args
wantListeners map[string]endpoint.ListenerSpec
wantErr bool
}{
{
name: "Test endpoints config",
args: args{
//language=yaml
config: `
listeners:
tcp_80:
name: ''
protocol: tcp
listenAddress: ''
port: 80
tcp_443:
name: ''
protocol: tcp
listenAddress: ''
port: 443
`,
},
wantListeners: map[string]endpoint.ListenerSpec{
"tcp_80": {
Name: "",
Protocol: "tcp",
Address: "",
Port: 80,
Endpoints: nil,
},
"tcp_443": {
Name: "",
Protocol: "tcp",
Address: "",
Port: 443,
Endpoints: nil,
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := CreateConfig()
if err := cfg.ReadConfigString(tt.args.config, "yaml"); (err != nil) != tt.wantErr {
t.Errorf("ReadConfig() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(tt.wantListeners, cfg.ListenerSpecs()) {
t.Errorf("want = %v, got = %v", tt.wantListeners, cfg.ListenerSpecs())
}
})
}
}