2020-04-27 22:26:15 +00:00
|
|
|
package config
|
2020-04-13 22:14:56 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2020-12-26 13:11:49 +00:00
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2020-04-13 22:14:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_handlerConfig_HandlerName(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
handlerName string
|
|
|
|
port uint16
|
|
|
|
listenAddress string
|
|
|
|
options *viper.Viper
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
2020-04-27 22:26:15 +00:00
|
|
|
name: "Get empty Handler for uninitialized struct",
|
2020-04-13 22:14:56 +00:00
|
|
|
fields: fields{},
|
|
|
|
want: "",
|
|
|
|
},
|
|
|
|
{
|
2020-04-27 22:26:15 +00:00
|
|
|
name: "Get expected Handler for initialized struct",
|
2020-04-13 22:14:56 +00:00
|
|
|
fields: fields{
|
|
|
|
handlerName: "sampleHandler",
|
|
|
|
},
|
|
|
|
want: "sampleHandler",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-04-27 22:26:15 +00:00
|
|
|
h := HandlerConfig{
|
|
|
|
HandlerName: tt.fields.handlerName,
|
|
|
|
Port: tt.fields.port,
|
|
|
|
ListenAddress: tt.fields.listenAddress,
|
|
|
|
Options: tt.fields.options,
|
2020-04-13 22:14:56 +00:00
|
|
|
}
|
2020-04-27 22:26:15 +00:00
|
|
|
if got := h.HandlerName; got != tt.want {
|
|
|
|
t.Errorf("Handler() = %v, want %v", got, tt.want)
|
2020-04-13 22:14:56 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_handlerConfig_ListenAddress(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
handlerName string
|
|
|
|
port uint16
|
|
|
|
listenAddress string
|
|
|
|
options *viper.Viper
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Get empty ListenAddress for uninitialized struct",
|
|
|
|
fields: fields{},
|
|
|
|
want: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Get expected ListenAddress for initialized struct",
|
|
|
|
fields: fields{
|
|
|
|
listenAddress: "0.0.0.0",
|
|
|
|
},
|
|
|
|
want: "0.0.0.0",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-04-27 22:26:15 +00:00
|
|
|
h := HandlerConfig{
|
|
|
|
HandlerName: tt.fields.handlerName,
|
|
|
|
Port: tt.fields.port,
|
|
|
|
ListenAddress: tt.fields.listenAddress,
|
|
|
|
Options: tt.fields.options,
|
2020-04-13 22:14:56 +00:00
|
|
|
}
|
2020-04-27 22:26:15 +00:00
|
|
|
if got := h.ListenAddress; got != tt.want {
|
2020-04-13 22:14:56 +00:00
|
|
|
t.Errorf("ListenAddress() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_handlerConfig_Options(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
handlerName string
|
|
|
|
port uint16
|
|
|
|
listenAddress string
|
|
|
|
options *viper.Viper
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want *viper.Viper
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Get nil Options for uninitialized struct",
|
|
|
|
fields: fields{},
|
|
|
|
want: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Get expected Options for initialized struct",
|
|
|
|
fields: fields{
|
|
|
|
options: viper.New(),
|
|
|
|
},
|
|
|
|
want: viper.New(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-04-27 22:26:15 +00:00
|
|
|
h := HandlerConfig{
|
|
|
|
HandlerName: tt.fields.handlerName,
|
|
|
|
Port: tt.fields.port,
|
|
|
|
ListenAddress: tt.fields.listenAddress,
|
|
|
|
Options: tt.fields.options,
|
2020-04-13 22:14:56 +00:00
|
|
|
}
|
2020-04-27 22:26:15 +00:00
|
|
|
if got := h.Options; !reflect.DeepEqual(got, tt.want) {
|
2020-04-13 22:14:56 +00:00
|
|
|
t.Errorf("Options() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_handlerConfig_Port(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
handlerName string
|
|
|
|
port uint16
|
|
|
|
listenAddress string
|
|
|
|
options *viper.Viper
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want uint16
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Get empty Port for uninitialized struct",
|
|
|
|
fields: fields{},
|
|
|
|
want: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Get expected Port for initialized struct",
|
|
|
|
fields: fields{
|
|
|
|
port: 80,
|
|
|
|
},
|
|
|
|
want: 80,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-04-27 22:26:15 +00:00
|
|
|
h := HandlerConfig{
|
|
|
|
HandlerName: tt.fields.handlerName,
|
|
|
|
Port: tt.fields.port,
|
|
|
|
ListenAddress: tt.fields.listenAddress,
|
|
|
|
Options: tt.fields.options,
|
2020-04-13 22:14:56 +00:00
|
|
|
}
|
2020-04-27 22:26:15 +00:00
|
|
|
if got := h.Port; got != tt.want {
|
2020-04-13 22:14:56 +00:00
|
|
|
t.Errorf("Port() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|