mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated tests in engine/sessions/utils
This commit is contained in:
committed by
Dan Christian Bogos
parent
783b6040d8
commit
6f067845a1
56
engine/libcdre_it_test.go
Normal file
56
engine/libcdre_it_test.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// +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 engine
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
)
|
||||
|
||||
func TestWriteFailedPosts(t *testing.T) {
|
||||
// can't convert
|
||||
var notanExportEvent string
|
||||
writeFailedPosts("somestring", notanExportEvent)
|
||||
// can convert & write
|
||||
dir := "/tmp/engine/libcdre_test/"
|
||||
exportEvent := &ExportEvents{
|
||||
module: "module",
|
||||
}
|
||||
if err := os.RemoveAll(dir); err != nil {
|
||||
t.Fatal("Error removing folder: ", dir, err)
|
||||
}
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
t.Fatal("Error creating folder: ", dir, err)
|
||||
}
|
||||
config.CgrConfig().GeneralCfg().FailedPostsDir = dir
|
||||
writeFailedPosts("itmID", exportEvent)
|
||||
|
||||
if filename, err := filepath.Glob(filepath.Join(dir, "*.gob")); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(filename) == 0 {
|
||||
t.Error("Expecting one file")
|
||||
} else if len(filename) > 1 {
|
||||
t.Error("Expecting only one file")
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,35 @@ var attrs = &engine.AttrSProcessEventReply{
|
||||
},
|
||||
}
|
||||
|
||||
func TestIsIndexed(t *testing.T) {
|
||||
sS := &SessionS{}
|
||||
if sS.isIndexed(&Session{CGRID: "test"}, true) {
|
||||
t.Error("Expecting: false, received: true")
|
||||
}
|
||||
if sS.isIndexed(&Session{CGRID: "test"}, false) {
|
||||
t.Error("Expecting: false, received: true")
|
||||
}
|
||||
sS = &SessionS{
|
||||
aSessions: map[string]*Session{"test": &Session{CGRID: "test"}},
|
||||
}
|
||||
if !sS.isIndexed(&Session{CGRID: "test"}, false) {
|
||||
t.Error("Expecting: true, received: false")
|
||||
}
|
||||
if sS.isIndexed(&Session{CGRID: "test"}, true) {
|
||||
t.Error("Expecting: true, received: false")
|
||||
}
|
||||
|
||||
sS = &SessionS{
|
||||
pSessions: map[string]*Session{"test": &Session{CGRID: "test"}},
|
||||
}
|
||||
if !sS.isIndexed(&Session{CGRID: "test"}, true) {
|
||||
t.Error("Expecting: false, received: true")
|
||||
}
|
||||
if sS.isIndexed(&Session{CGRID: "test"}, false) {
|
||||
t.Error("Expecting: false, received: true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSIndexAndUnindexSessions(t *testing.T) {
|
||||
sSCfg, _ := config.NewDefaultCGRConfig()
|
||||
sSCfg.SessionSCfg().SessionIndexes = utils.StringMap{
|
||||
|
||||
84
utils/set_test.go
Normal file
84
utils/set_test.go
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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 utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewStringSet(t *testing.T) {
|
||||
input := []string{}
|
||||
exp := &StringSet{data: make(map[string]struct{})}
|
||||
if rcv := NewStringSet(input); !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected: %+v, received: %+v", exp, rcv)
|
||||
}
|
||||
input = []string{"test"}
|
||||
exp.AddSlice(input)
|
||||
if rcv := NewStringSet(input); !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected: %+v, received: %+v", exp, rcv)
|
||||
}
|
||||
input = []string{"test1", "test2", "test3"}
|
||||
exp = &StringSet{data: make(map[string]struct{})}
|
||||
exp.AddSlice(input)
|
||||
if rcv := NewStringSet(input); !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected: %+v, received: %+v", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdd(t *testing.T){
|
||||
s := &StringSet{data: map[string]struct{}{}}
|
||||
eOut := &StringSet{data: map[string]struct{}{
|
||||
"test" : struct{}{},
|
||||
}}
|
||||
if reflect.DeepEqual(eOut,s){
|
||||
t.Errorf("Expecting: %+v, received: %+v",eOut,s)
|
||||
}
|
||||
s.Add("test")
|
||||
if !reflect.DeepEqual(eOut,s){
|
||||
t.Errorf("Expecting: %+v, received: %+v",eOut,s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemove(t *testing.T){
|
||||
eOut := &StringSet{data: map[string]struct{}{}}
|
||||
s := &StringSet{data: map[string]struct{}{
|
||||
"test" : struct{}{},
|
||||
}}
|
||||
if reflect.DeepEqual(eOut,s){
|
||||
t.Errorf("Expecting: %+v, received: %+v",eOut,s)
|
||||
}
|
||||
s.Remove("test")
|
||||
if !reflect.DeepEqual(eOut,s){
|
||||
t.Errorf("Expecting: %+v, received: %+v",eOut,s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHas(t *testing.T){
|
||||
s := &StringSet{}
|
||||
if s.Has("test"){
|
||||
t.Error("Expecting: false, received: true")
|
||||
}
|
||||
s = &StringSet{data: map[string]struct{}{
|
||||
"test" : struct{}{},
|
||||
}}
|
||||
if !s.Has("test"){
|
||||
t.Error("Expecting: true, received: false")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user