2019-08-06 19:53:14 +03:00
|
|
|
package monitor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMonitor(t *testing.T) {
|
|
|
|
// create new monitor
|
|
|
|
m := NewMonitor()
|
|
|
|
|
2019-08-06 21:02:57 +03:00
|
|
|
if err := m.Run(); err != nil {
|
|
|
|
t.Fatalf("failed to stop monitor: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-08-06 19:53:14 +03:00
|
|
|
services := []string{"foo", "bar", "baz"}
|
|
|
|
|
|
|
|
for _, service := range services {
|
|
|
|
_, err := m.Status(service)
|
2019-08-06 20:05:05 +03:00
|
|
|
if err == nil {
|
2019-08-06 19:53:14 +03:00
|
|
|
t.Fatal("expected status error for unknown service")
|
|
|
|
}
|
2019-08-06 20:05:05 +03:00
|
|
|
|
|
|
|
if err := m.Watch(service); err == nil {
|
|
|
|
t.Fatal("expected watch error for unknown service")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// 1. start a service
|
|
|
|
// 2. watch service
|
|
|
|
// 3. get service status
|
2019-08-06 19:53:14 +03:00
|
|
|
}
|
2019-08-06 20:05:05 +03:00
|
|
|
|
|
|
|
// stop monitor
|
2019-08-06 21:02:57 +03:00
|
|
|
if err := m.Stop(); err != nil {
|
|
|
|
t.Fatalf("failed to stop monitor: %v", err)
|
|
|
|
}
|
2019-08-06 19:53:14 +03:00
|
|
|
}
|