2015-03-12 22:21:11 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadConfigFile(t *testing.T) {
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config.hcl")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Listeners: []*Listener{
|
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"address": "127.0.0.1:443",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Backend: &Backend{
|
2015-04-17 18:25:20 +00:00
|
|
|
Type: "consul",
|
|
|
|
AdvertiseAddr: "foo",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
2015-04-17 18:21:40 +00:00
|
|
|
|
2015-04-28 22:09:09 +00:00
|
|
|
DisableMlock: true,
|
2015-04-17 18:21:40 +00:00
|
|
|
StatsiteAddr: "foo",
|
|
|
|
StatsdAddr: "bar",
|
2015-03-12 22:21:11 +00:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config, expected) {
|
|
|
|
t.Fatalf("bad: %#v", config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_json(t *testing.T) {
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config.hcl.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Listeners: []*Listener{
|
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"address": "127.0.0.1:443",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Backend: &Backend{
|
|
|
|
Type: "consul",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config, expected) {
|
|
|
|
t.Fatalf("bad: %#v", config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigFile_json2(t *testing.T) {
|
|
|
|
config, err := LoadConfigFile("./test-fixtures/config2.hcl.json")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Listeners: []*Listener{
|
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"address": "127.0.0.1:443",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Backend: &Backend{
|
|
|
|
Type: "consul",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config, expected) {
|
|
|
|
t.Fatalf("bad: %#v", config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadConfigDir(t *testing.T) {
|
|
|
|
config, err := LoadConfigDir("./test-fixtures/config-dir")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := &Config{
|
|
|
|
Listeners: []*Listener{
|
|
|
|
&Listener{
|
|
|
|
Type: "tcp",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"address": "127.0.0.1:443",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Backend: &Backend{
|
|
|
|
Type: "consul",
|
2015-03-13 17:09:38 +00:00
|
|
|
Config: map[string]string{
|
2015-03-12 22:21:11 +00:00
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(config, expected) {
|
|
|
|
t.Fatalf("bad: %#v", config)
|
|
|
|
}
|
|
|
|
}
|