mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Tests in services
This commit is contained in:
committed by
Dan Christian Bogos
parent
bb9b6ba174
commit
bc6701a6e6
@@ -97,6 +97,10 @@ func TestActionSCoverage(t *testing.T) {
|
||||
if !actS2.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
errStart := actS2.Start()
|
||||
if errStart == nil || errStart != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, errStart)
|
||||
}
|
||||
serviceName := actS2.ServiceName()
|
||||
if !reflect.DeepEqual(serviceName, utils.ActionS) {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ActionS, serviceName)
|
||||
@@ -117,4 +121,8 @@ func TestActionSCoverage(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
if actS2.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ func TestNewAnalyzerCoverage(t *testing.T) {
|
||||
filterSChan: filterSChan,
|
||||
shdChan: shdChan,
|
||||
srvDep: srvDep,
|
||||
stopChan: make(chan struct{}, 1),
|
||||
}
|
||||
if anz2.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
@@ -63,7 +64,14 @@ func TestNewAnalyzerCoverage(t *testing.T) {
|
||||
if !anz2.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := anz2.Reload()
|
||||
if !anz2.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
err := anz2.Start()
|
||||
if err == nil || err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
}
|
||||
err = anz2.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,10 @@ func TestAsteriskAgentReload(t *testing.T) {
|
||||
if !srv.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
srvReload := srv.Reload()
|
||||
if srvReload != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", srvReload)
|
||||
}
|
||||
err := srv.Start()
|
||||
if err != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
|
||||
|
||||
@@ -75,4 +75,16 @@ func TestDispatcherHCoverage(t *testing.T) {
|
||||
if !reflect.DeepEqual(shouldRun, false) {
|
||||
t.Errorf("\nExpecting <false>,\n Received <%+v>", shouldRun)
|
||||
}
|
||||
if !srv2.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
srv2.stopChan = make(chan struct{}, 1)
|
||||
srv2.dspS = dispatcherh.NewDispatcherHService(cfg, cM)
|
||||
shutdownSrv := srv2.Shutdown()
|
||||
if shutdownSrv != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", shutdownSrv)
|
||||
}
|
||||
if srv2.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ func TestFreeSwitchAgentReload(t *testing.T) {
|
||||
shdChan := utils.NewSyncedChan()
|
||||
shdWg := new(sync.WaitGroup)
|
||||
chS := engine.NewCacheS(cfg, nil, nil)
|
||||
|
||||
cacheSChan := make(chan rpcclient.ClientConnector, 1)
|
||||
cacheSChan <- chS
|
||||
|
||||
@@ -81,7 +80,6 @@ func TestFreeSwitchAgentReload(t *testing.T) {
|
||||
if srv.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
|
||||
shdChan.CloseOnce()
|
||||
runtime.Gosched()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
@@ -74,4 +74,11 @@ func TestHTTPAgentCoverage(t *testing.T) {
|
||||
if rld != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", rld)
|
||||
}
|
||||
shutdownError := srv.Shutdown()
|
||||
if shutdownError != nil {
|
||||
t.Errorf("\nExpecting <nil>,\n Received <%+v>", shutdownError)
|
||||
}
|
||||
if srv.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
@@ -32,8 +34,29 @@ func TestStorDBServiceCoverage(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
|
||||
srv := NewStorDBService(cfg, srvDep)
|
||||
if srv.IsRunning() {
|
||||
err := srv.IsRunning()
|
||||
if err == true {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
srv.db = engine.NewInternalDB([]string{"test"}, []string{"test2"}, true)
|
||||
err = srv.IsRunning()
|
||||
if err == false {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
|
||||
err2 := srv.Start()
|
||||
if err2 == nil || err2 != utils.ErrServiceAlreadyRunning {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err2)
|
||||
}
|
||||
srv.oldDBCfg = &config.StorDbCfg{
|
||||
Type: utils.INTERNAL,
|
||||
Host: "test_host",
|
||||
Port: "test_port",
|
||||
Name: "test_name",
|
||||
User: "test_user",
|
||||
Password: "test_pass",
|
||||
}
|
||||
err2 = srv.Reload()
|
||||
if err2 == nil {
|
||||
t.Errorf("\nExpecting <Error 1045: Access denied for user 'cgrates'@'localhost' (using password: NO)>,\n Received <%+v>", err2)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user