orbiter/core/daemon_test.go
Gianluca Arbezzano db7f674976 Bootstrap autodetection and swarm zero conf
Fixed #9

This PR bootstrap the autodetection feature:

1. It works when the configuration file is not setup. Right know I am
not going to manage the merge of double sources (autodetection and
configuration file).

2. At the moment only Docker Swarm will support this feature.
2017-03-14 23:49:53 +00:00

97 lines
1.8 KiB
Go

package core
import "testing"
func TestNewCore(t *testing.T) {
conf := map[string]AutoscalerConf{
"first-scaler": AutoscalerConf{
Provider: "fake",
Parameters: map[string]string{},
Policies: map[string]PolicyConf{
"frontend": PolicyConf{
Up: 3,
Down: 10,
},
},
},
"second-scaler": AutoscalerConf{
Provider: "fake",
Parameters: map[string]string{},
Policies: map[string]PolicyConf{
"micro": PolicyConf{
Up: 6,
Down: 2,
},
"service": PolicyConf{
Up: 3,
Down: 1,
},
},
},
}
core, err := NewCoreByConfig(conf)
if err != nil {
t.Fatal(err)
}
if len(core.Autoscalers) != 3 {
t.Fatalf("This core needs to have 2 autoscalers. Not %d", len(core.Autoscalers))
}
}
func TestGetSingleAutoscaler(t *testing.T) {
conf := map[string]AutoscalerConf{
"second": AutoscalerConf{
Provider: "fake",
Parameters: map[string]string{},
Policies: map[string]PolicyConf{
"micro": PolicyConf{
Up: 6,
Down: 2,
},
"service": PolicyConf{
Up: 3,
Down: 1,
},
},
},
}
core, _ := NewCoreByConfig(conf)
_, ok := core.Autoscalers["second/micro"]
if ok == false {
t.Fatal("micro exist")
}
}
func TestNewCoreWithUnsupportedProvider(t *testing.T) {
conf := map[string]AutoscalerConf{
"second-scaler": AutoscalerConf{
Provider: "fake",
Parameters: map[string]string{},
Policies: map[string]PolicyConf{
"micro": PolicyConf{
Up: 6,
Down: 2,
},
"service": PolicyConf{
Up: 3,
Down: 1,
},
},
},
"first-scaler": AutoscalerConf{
Provider: "lalala",
Parameters: map[string]string{},
Policies: map[string]PolicyConf{
"frontend": PolicyConf{
Up: 3,
Down: 10,
},
},
},
}
_, err := NewCoreByConfig(conf)
if err.Error() != "lalala not supported." {
t.Fatal(err)
}
}