2019-01-30 19:48:50 +00:00
|
|
|
package operations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
2019-03-19 23:07:49 +00:00
|
|
|
var _ = OperationFeeds(&Service{})
|
2019-07-26 17:07:20 +00:00
|
|
|
var _ = Pool(&Service{})
|
2019-03-19 23:07:49 +00:00
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestStop_OK(t *testing.T) {
|
2019-01-30 19:48:50 +00:00
|
|
|
hook := logTest.NewGlobal()
|
2019-09-07 02:39:14 +00:00
|
|
|
opsService := NewService(context.Background(), &Config{})
|
2019-01-30 19:48:50 +00:00
|
|
|
|
|
|
|
if err := opsService.Stop(); err != nil {
|
|
|
|
t.Fatalf("Unable to stop operation service: %v", err)
|
|
|
|
}
|
|
|
|
// The context should have been canceled.
|
|
|
|
if opsService.ctx.Err() != context.Canceled {
|
|
|
|
t.Error("context was not canceled")
|
|
|
|
}
|
|
|
|
hook.Reset()
|
|
|
|
}
|
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestServiceStatus_Error(t *testing.T) {
|
2019-09-07 02:39:14 +00:00
|
|
|
service := NewService(context.Background(), &Config{})
|
2019-01-30 19:48:50 +00:00
|
|
|
if service.Status() != nil {
|
2019-01-31 18:54:24 +00:00
|
|
|
t.Errorf("service status should be nil to begin with, got: %v", service.error)
|
2019-01-30 19:48:50 +00:00
|
|
|
}
|
2019-01-31 18:54:24 +00:00
|
|
|
err := errors.New("error error error")
|
|
|
|
service.error = err
|
2019-01-30 19:48:50 +00:00
|
|
|
|
2019-01-31 18:54:24 +00:00
|
|
|
if service.Status() != err {
|
|
|
|
t.Error("service status did not return wanted err")
|
2019-01-30 19:48:50 +00:00
|
|
|
}
|
|
|
|
}
|