mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add new unit tests on services
This commit is contained in:
committed by
Dan Christian Bogos
parent
5905b54f7f
commit
ea149965ae
@@ -87,3 +87,10 @@ func TestAnalyzerCoverage(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
func TestAnalyzerServiceReload(t *testing.T) {
|
||||
analyzerService := &AnalyzerService{}
|
||||
err := analyzerService.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected Reload to return no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,3 +111,11 @@ func TestApiersCoverage(t *testing.T) {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, shutdownApi2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAPIerSv2ServiceReload(t *testing.T) {
|
||||
apiService := &APIerSv2Service{}
|
||||
err := apiService.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected Reload to return no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,3 +85,11 @@ func TestAttributeSCoverage(t *testing.T) {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttributeServiceReload(t *testing.T) {
|
||||
attrService := &AttributeService{}
|
||||
err := attrService.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected Reload to return no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,3 +93,11 @@ func TestCdrsCoverage(t *testing.T) {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDRServerReload(t *testing.T) {
|
||||
cdrService := &CDRServer{}
|
||||
err := cdrService.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected Reload to return no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,3 +86,11 @@ func TestChargerSCoverage(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestChargerServiceReload(t *testing.T) {
|
||||
chargerService := &ChargerService{}
|
||||
err := chargerService.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected Reload to return no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,3 +81,11 @@ func TestCoreSCoverage(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCoreServiceReload(t *testing.T) {
|
||||
coreService := &CoreService{}
|
||||
err := coreService.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected Reload to return no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,3 +61,11 @@ func TestJanusAgentCoverage(t *testing.T) {
|
||||
t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.JanusAgent, serviceName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJanusAgentReload(t *testing.T) {
|
||||
ja := &JanusAgent{}
|
||||
err := ja.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
119
services/rankings_test.go
Normal file
119
services/rankings_test.go
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
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 (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/cores"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestRankingServiceServiceName(t *testing.T) {
|
||||
expectedServiceName := utils.RankingS
|
||||
rankingService := &RankingService{}
|
||||
result := rankingService.ServiceName()
|
||||
if result != expectedServiceName {
|
||||
t.Errorf("Expected ServiceName to return %v, got %v", expectedServiceName, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRankingServiceReload(t *testing.T) {
|
||||
rankingService := &RankingService{}
|
||||
err := rankingService.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected Reload to return no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRankingService(t *testing.T) {
|
||||
cfg := &config.CGRConfig{}
|
||||
dm := &DataDBService{}
|
||||
cacheS := &engine.CacheS{}
|
||||
filterSChan := make(chan *engine.FilterS)
|
||||
server := &cores.Server{}
|
||||
internalRankingSChan := make(chan birpc.ClientConnector)
|
||||
connMgr := &engine.ConnManager{}
|
||||
anz := &AnalyzerService{}
|
||||
srvDep := make(map[string]*sync.WaitGroup)
|
||||
service := NewRankingService(
|
||||
cfg,
|
||||
dm,
|
||||
cacheS,
|
||||
filterSChan,
|
||||
server,
|
||||
internalRankingSChan,
|
||||
connMgr,
|
||||
anz,
|
||||
srvDep,
|
||||
)
|
||||
rankingService, ok := service.(*RankingService)
|
||||
|
||||
if !ok {
|
||||
t.Fatalf("Expected *RankingService, got %T", service)
|
||||
}
|
||||
|
||||
if rankingService.cfg != cfg {
|
||||
t.Errorf("Expected cfg field to be %v, got %v", cfg, rankingService.cfg)
|
||||
}
|
||||
|
||||
if rankingService.dm != dm {
|
||||
t.Errorf("Expected dm field to be %v, got %v", dm, rankingService.dm)
|
||||
}
|
||||
|
||||
if rankingService.cacheS != cacheS {
|
||||
t.Errorf("Expected cacheS field to be %v, got %v", cacheS, rankingService.cacheS)
|
||||
}
|
||||
|
||||
if rankingService.filterSChan != filterSChan {
|
||||
t.Errorf("Expected filterSChan field to be %v, got %v", filterSChan, rankingService.filterSChan)
|
||||
}
|
||||
|
||||
if rankingService.server != server {
|
||||
t.Errorf("Expected server field to be %v, got %v", server, rankingService.server)
|
||||
}
|
||||
|
||||
if rankingService.connChan != internalRankingSChan {
|
||||
t.Errorf("Expected connChan field to be %v, got %v", internalRankingSChan, rankingService.connChan)
|
||||
}
|
||||
|
||||
if rankingService.connMgr != connMgr {
|
||||
t.Errorf("Expected connMgr field to be %v, got %v", connMgr, rankingService.connMgr)
|
||||
}
|
||||
|
||||
if rankingService.anz != anz {
|
||||
t.Errorf("Expected anz field to be %v, got %v", anz, rankingService.anz)
|
||||
}
|
||||
|
||||
if len(rankingService.srvDep) != len(srvDep) {
|
||||
t.Errorf("Expected srvDep to have %d entries, got %d", len(srvDep), len(rankingService.srvDep))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsRunning(t *testing.T) {
|
||||
rg := &RankingService{}
|
||||
result := rg.IsRunning()
|
||||
if result != false {
|
||||
t.Errorf("Expected IsRunning to return false, got %v", result)
|
||||
}
|
||||
}
|
||||
@@ -79,3 +79,11 @@ func TestSupplierSCoverage(t *testing.T) {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoutesReload(t *testing.T) {
|
||||
routeS := &RouteService{}
|
||||
err := routeS.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,3 +82,11 @@ func TestSessionSCoverage(t *testing.T) {
|
||||
t.Errorf("\nExpecting <false>,\n Received <%+v>", shouldRun)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReload(t *testing.T) {
|
||||
smg := &SessionService{}
|
||||
err := smg.Reload()
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
105
services/trends_test.go
Normal file
105
services/trends_test.go
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
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 (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/cores"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestTrendServiceReload(t *testing.T) {
|
||||
trendService := &TrendService{}
|
||||
if err := trendService.Reload(); err != nil {
|
||||
t.Errorf("Reload() expected no error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewTrendService(t *testing.T) {
|
||||
|
||||
cfg := &config.CGRConfig{}
|
||||
dm := &DataDBService{}
|
||||
cacheS := &engine.CacheS{}
|
||||
filterSChan := make(chan *engine.FilterS)
|
||||
server := &cores.Server{}
|
||||
internalStatSChan := make(chan birpc.ClientConnector)
|
||||
connMgr := &engine.ConnManager{}
|
||||
anz := &AnalyzerService{}
|
||||
srvDep := make(map[string]*sync.WaitGroup)
|
||||
service := NewTrendService(cfg, dm, cacheS, filterSChan, server, internalStatSChan, connMgr, anz, srvDep)
|
||||
trendService, ok := service.(*TrendService)
|
||||
|
||||
if !ok {
|
||||
t.Fatalf("Expected *TrendService, got %T", service)
|
||||
}
|
||||
|
||||
if trendService.cfg != cfg {
|
||||
t.Errorf("Expected cfg field to be %v, got %v", cfg, trendService.cfg)
|
||||
}
|
||||
|
||||
if trendService.dm != dm {
|
||||
t.Errorf("Expected dm field to be %v, got %v", dm, trendService.dm)
|
||||
}
|
||||
|
||||
if trendService.cacheS != cacheS {
|
||||
t.Errorf("Expected cacheS field to be %v, got %v", cacheS, trendService.cacheS)
|
||||
}
|
||||
|
||||
if trendService.filterSChan != filterSChan {
|
||||
t.Errorf("Expected filterSChan field to be %v, got %v", filterSChan, trendService.filterSChan)
|
||||
}
|
||||
|
||||
if trendService.server != server {
|
||||
t.Errorf("Expected server field to be %v, got %v", server, trendService.server)
|
||||
}
|
||||
|
||||
if trendService.connChan != internalStatSChan {
|
||||
t.Errorf("Expected internalStatSChan field to be %v, got %v", internalStatSChan, trendService.connChan)
|
||||
}
|
||||
|
||||
if trendService.connMgr != connMgr {
|
||||
t.Errorf("Expected connMgr field to be %v, got %v", connMgr, trendService.connMgr)
|
||||
}
|
||||
|
||||
if trendService.anz != anz {
|
||||
t.Errorf("Expected anz field to be %v, got %v", anz, trendService.anz)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestTrendServiceServiceName(t *testing.T) {
|
||||
trendService := &TrendService{}
|
||||
name := trendService.ServiceName()
|
||||
if name != utils.TrendS {
|
||||
t.Errorf("Expected ServiceName to return %s, got %s", utils.TrendS, name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrendServiceIsRunning(t *testing.T) {
|
||||
trendService := &TrendService{}
|
||||
result := trendService.IsRunning()
|
||||
if result != false {
|
||||
t.Errorf("Expected IsRunning to return false, got %v", result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user