Coverage tests in services

This commit is contained in:
andronache
2020-12-20 16:19:59 +02:00
committed by Dan Christian Bogos
parent ac2521d04e
commit c5aab60e2d
14 changed files with 10 additions and 254 deletions

View File

@@ -0,0 +1 @@
package services

View File

@@ -0,0 +1 @@
package services

View File

@@ -1,74 +0,0 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package services
import (
"reflect"
"sync"
"testing"
"github.com/cgrates/cgrates/loaders"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
)
//TestLoaderSCoverage for cover testing
func TestLoaderSCoverage(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
shdChan := utils.NewSyncedChan()
filterSChan := make(chan *engine.FilterS, 1)
filterSChan <- nil
server := cores.NewServer(nil)
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
db := NewDataDBService(cfg, nil, srvDep)
internalLoaderSChan := make(chan rpcclient.ClientConnector, 1)
rpcInternal := map[string]chan rpcclient.ClientConnector{}
cM := engine.NewConnManager(cfg, rpcInternal)
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
srv := NewLoaderService(cfg, db,
filterSChan, server, internalLoaderSChan,
cM, anz, srvDep)
if srv == nil {
t.Errorf("\nExpecting <nil>,\n Received <%+v>", utils.ToJSON(srv))
}
if srv.IsRunning() {
t.Errorf("Expected service to be down")
}
srv.ldrs = loaders.NewLoaderService(&engine.DataManager{}, []*config.LoaderSCfg{{
ID: "test_id",
Enabled: true,
}},
"test", &engine.FilterS{}, &engine.ConnManager{})
if !srv.IsRunning() {
t.Errorf("Expected service to be running")
}
if !reflect.DeepEqual(srv.GetLoaderS(), srv.ldrs) {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", srv.ldrs, srv.GetLoaderS())
}
errStart := srv.Start()
if errStart == nil || errStart != utils.ErrServiceAlreadyRunning {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, errStart)
}
}

1
services/loaders_test.go Normal file
View File

@@ -0,0 +1 @@
package services

View File

@@ -0,0 +1 @@
package services

1
services/rals_test.go Normal file
View File

@@ -0,0 +1 @@
package services

1
services/rates_test.go Normal file
View File

@@ -0,0 +1 @@
package services

View File

@@ -0,0 +1 @@
package services

View File

@@ -1,76 +0,0 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package services
import (
"reflect"
"sync"
"testing"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/config"
)
//TestResponderCoverage for cover testing
func TestResponderCoverage(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
server := cores.NewServer(nil)
internalChan := make(chan rpcclient.ClientConnector, 1)
shdChan := utils.NewSyncedChan()
filterSChan := make(chan *engine.FilterS, 1)
filterSChan <- nil
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
anz := NewAnalyzerService(cfg, server, filterSChan,
shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
srv := NewResponderService(cfg, server, internalChan,
shdChan, anz, srvDep)
if srv == nil {
t.Errorf("\nExpecting <nil>,\n Received <%+v>", utils.ToJSON(srv))
}
if srv.IsRunning() {
t.Errorf("Expected service to be down")
}
srv.resp = &engine.Responder{}
if !srv.IsRunning() {
t.Errorf("Expected service to be running")
}
err := srv.Start()
if err == nil || err != utils.ErrServiceAlreadyRunning {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
}
serviceName := srv.ServiceName()
if !reflect.DeepEqual(serviceName, utils.ResponderS) {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ResponderS, serviceName)
}
getResponder := srv.GetResponder()
if !reflect.DeepEqual(getResponder, srv.resp) {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", srv.resp, getResponder)
}
shouldRun := srv.ShouldRun()
if !reflect.DeepEqual(shouldRun, false) {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", false, shouldRun)
}
}

View File

@@ -0,0 +1 @@
package services

View File

@@ -1,104 +0,0 @@
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package services
import (
"path"
"sync"
"testing"
"time"
"github.com/cgrates/rpcclient"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/servmanager"
"github.com/cgrates/cgrates/utils"
)
func TestSupplierSReload(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
utils.Logger.SetLogLevel(7)
cfg.StatSCfg().Enabled = true
filterSChan := make(chan *engine.FilterS, 1)
filterSChan <- nil
shdChan := utils.NewSyncedChan()
shdWg := new(sync.WaitGroup)
chS := engine.NewCacheS(cfg, nil, nil)
close(chS.GetPrecacheChannel(utils.CacheRouteProfiles))
close(chS.GetPrecacheChannel(utils.CacheRouteFilterIndexes))
close(chS.GetPrecacheChannel(utils.CacheStatQueueProfiles))
close(chS.GetPrecacheChannel(utils.CacheStatQueues))
close(chS.GetPrecacheChannel(utils.CacheStatFilterIndexes))
server := cores.NewServer(nil)
srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg)
srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
db := NewDataDBService(cfg, nil, srvDep)
anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep)
sts := NewStatService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
supS := NewRouteService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep)
engine.NewConnManager(cfg, nil)
srvMngr.AddServices(supS, sts,
NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db)
if err := srvMngr.StartServices(); err != nil {
t.Error(err)
}
if supS.IsRunning() {
t.Errorf("Expected service to be down")
}
if db.IsRunning() {
t.Errorf("Expected service to be down")
}
var reply string
if err := cfg.V1ReloadConfig(&config.ReloadArgs{
Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongonew"),
Section: config.RouteSJson,
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Errorf("Expecting OK ,received %s", reply)
}
time.Sleep(10 * time.Millisecond) //need to switch to gorutine
if !supS.IsRunning() {
t.Errorf("Expected service to be running")
}
if !db.IsRunning() {
t.Errorf("Expected service to be running")
}
err := supS.Start()
if err == nil || err != utils.ErrServiceAlreadyRunning {
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
}
err = supS.Reload()
if err != nil {
t.Errorf("\nExpecting <nil>,\n Received <%+v>", err)
}
cfg.RouteSCfg().Enabled = false
cfg.GetReloadChan(config.RouteSJson) <- struct{}{}
time.Sleep(10 * time.Millisecond)
if supS.IsRunning() {
t.Errorf("Expected service to be down")
}
shdChan.CloseOnce()
time.Sleep(10 * time.Millisecond)
}

1
services/routes_test.go Normal file
View File

@@ -0,0 +1 @@
package services

View File

@@ -0,0 +1 @@
package services