mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 00:28:44 +05:00
149 lines
4.2 KiB
Go
149 lines
4.2 KiB
Go
/*
|
|
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 tpes
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/cgrates/birpc/context"
|
|
"github.com/cgrates/cgrates/config"
|
|
"github.com/cgrates/cgrates/engine"
|
|
"github.com/cgrates/cgrates/utils"
|
|
)
|
|
|
|
func TestTPEnewTPThresholds(t *testing.T) {
|
|
// dataDB := &engine.DataDBM
|
|
// dm := &engine.NewDataManager()
|
|
cfg := config.NewDefaultCGRConfig()
|
|
connMng := engine.NewConnManager(cfg)
|
|
dm := engine.NewDataManager(&engine.DataDBMock{
|
|
GetThresholdProfileDrvF: func(ctx *context.Context, tnt string, id string) (*engine.ThresholdProfile, error) {
|
|
thd := &engine.ThresholdProfile{
|
|
Tenant: "cgrates.org",
|
|
ID: "THD_2",
|
|
FilterIDs: []string{"*string:~*req.Account:1001"},
|
|
ActionProfileIDs: []string{"actPrfID"},
|
|
MaxHits: 7,
|
|
MinHits: 0,
|
|
Weights: utils.DynamicWeights{
|
|
{
|
|
Weight: 20,
|
|
},
|
|
},
|
|
Async: true,
|
|
}
|
|
return thd, nil
|
|
},
|
|
}, nil, connMng)
|
|
exp := &TPThresholds{
|
|
dm: dm,
|
|
}
|
|
rcv := newTPThresholds(dm)
|
|
if rcv.dm != exp.dm {
|
|
t.Errorf("Expected %v \nbut received %v", exp, rcv)
|
|
}
|
|
}
|
|
|
|
func TestTPEExportThresholds(t *testing.T) {
|
|
wrtr := new(bytes.Buffer)
|
|
cfg := config.NewDefaultCGRConfig()
|
|
data := engine.NewInternalDB(nil, nil, cfg.DataDbCfg().Items)
|
|
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
|
tpThd := TPThresholds{
|
|
dm: dm,
|
|
}
|
|
thd := &engine.ThresholdProfile{
|
|
Tenant: "cgrates.org",
|
|
ID: "THD_2",
|
|
FilterIDs: []string{"*string:~*req.Account:1001"},
|
|
ActionProfileIDs: []string{"actPrfID"},
|
|
MaxHits: 7,
|
|
MinHits: 0,
|
|
Weights: utils.DynamicWeights{
|
|
{
|
|
Weight: 20,
|
|
},
|
|
},
|
|
Async: true,
|
|
}
|
|
tpThd.dm.SetThresholdProfile(context.Background(), thd, false)
|
|
err := tpThd.exportItems(context.Background(), wrtr, "cgrates.org", []string{"THD_2"})
|
|
if err != nil {
|
|
t.Errorf("Expected nil\n but received %v", err)
|
|
}
|
|
}
|
|
|
|
func TestTPEExportItemsThresholdsNoDbConn(t *testing.T) {
|
|
engine.Cache.Clear(nil)
|
|
wrtr := new(bytes.Buffer)
|
|
tpThd := TPThresholds{
|
|
dm: nil,
|
|
}
|
|
thd := &engine.ThresholdProfile{
|
|
Tenant: "cgrates.org",
|
|
ID: "THD_2",
|
|
FilterIDs: []string{"*string:~*req.Account:1001"},
|
|
ActionProfileIDs: []string{"actPrfID"},
|
|
MaxHits: 7,
|
|
MinHits: 0,
|
|
Weights: utils.DynamicWeights{
|
|
{
|
|
Weight: 20,
|
|
},
|
|
},
|
|
Async: true,
|
|
}
|
|
tpThd.dm.SetThresholdProfile(context.Background(), thd, false)
|
|
err := tpThd.exportItems(context.Background(), wrtr, "cgrates.org", []string{"THD_2"})
|
|
if err != utils.ErrNoDatabaseConn {
|
|
t.Errorf("Expected %v\n but received %v", utils.ErrNoDatabaseConn, err)
|
|
}
|
|
}
|
|
|
|
func TestTPEExportItemsThresholdsIDNotFound(t *testing.T) {
|
|
wrtr := new(bytes.Buffer)
|
|
cfg := config.NewDefaultCGRConfig()
|
|
data := engine.NewInternalDB(nil, nil, cfg.DataDbCfg().Items)
|
|
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
|
|
tpThd := TPThresholds{
|
|
dm: dm,
|
|
}
|
|
thd := &engine.ThresholdProfile{
|
|
Tenant: "cgrates.org",
|
|
ID: "THD_2",
|
|
FilterIDs: []string{"*string:~*req.Account:1001"},
|
|
ActionProfileIDs: []string{"actPrfID"},
|
|
MaxHits: 7,
|
|
MinHits: 0,
|
|
Weights: utils.DynamicWeights{
|
|
{
|
|
Weight: 20,
|
|
},
|
|
},
|
|
Async: true,
|
|
}
|
|
tpThd.dm.SetThresholdProfile(context.Background(), thd, false)
|
|
err := tpThd.exportItems(context.Background(), wrtr, "cgrates.org", []string{"THD_3"})
|
|
errExpect := "<NOT_FOUND> cannot find ThresholdProfile with id: <THD_3>"
|
|
if err.Error() != errExpect {
|
|
t.Errorf("Expected %v\n but received %v", errExpect, err)
|
|
}
|
|
}
|