api/internal/app/rpc_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

71 lines
1.4 KiB
Go

package app
import (
"net/url"
"reflect"
"testing"
)
func TestRPC_ListenURL(t *testing.T) {
type fields struct {
Listen string
}
tests := []struct {
name string
fields fields
wantU *url.URL
}{
{
name: "Parse valid TCP URL",
fields: fields{
Listen: "tcp://localhost:8080",
},
wantU: func() *url.URL {
if u, e := url.Parse("tcp://localhost:8080"); e != nil {
t.Errorf("Error during URL parsing: %v", e)
return nil
} else {
return u
}
}(),
},
{
name: "Parse valid unix socket url",
fields: fields{
Listen: "unix:///var/run/inetmock.sock",
},
wantU: func() *url.URL {
if u, e := url.Parse("unix:///var/run/inetmock.sock"); e != nil {
t.Errorf("Error during URL parsing: %v", e)
return nil
} else {
return u
}
}(),
},
{
name: "Expect fallback value due to parse error",
fields: fields{
Listen: `"tcp;\\asdf:234sedf`,
},
wantU: func() *url.URL {
if u, e := url.Parse("tcp://:0"); e != nil {
t.Errorf("Error during URL parsing: %v", e)
return nil
} else {
return u
}
}(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := RPC{
Listen: tt.fields.Listen,
}
if gotU := r.ListenURL(); !reflect.DeepEqual(gotU, tt.wantU) {
t.Errorf("ListenURL() = %v, want %v", gotU, tt.wantU)
}
})
}
}