Finished tests for libers.go

This commit is contained in:
andronache
2021-03-09 15:19:04 +02:00
committed by Dan Christian Bogos
parent 981fec992e
commit 43cb84591e
2 changed files with 129 additions and 0 deletions

37
ers/libers_test.go Normal file
View File

@@ -0,0 +1,37 @@
/*
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 ers
import (
"reflect"
"testing"
)
func TestGetProcessOptions(t *testing.T) {
opts := map[string]interface{}{
"testKeyProcessed": "testValue",
}
result := getProcessOptions(opts)
expected := map[string]interface{}{
"testKey": "testValue",
}
if !reflect.DeepEqual(result, expected) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
}
}

View File

@@ -130,3 +130,95 @@ func TestS3ER(t *testing.T) {
}
close(rdrExit)
}
func TestNewS3ER(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
expected := &S3ER{
cgrCfg: cfg,
cfgIdx: 1,
fltrS: nil,
rdrEvents: nil,
rdrExit: nil,
rdrErr: nil,
cap: nil,
awsRegion: "",
awsID: "",
awsKey: "",
awsToken: "",
queueID: "cgrates_cdrs",
session: nil,
poster: nil,
}
cfg.ERsCfg().Readers = []*config.EventReaderCfg{
{
ID: utils.MetaDefault,
Type: utils.MetaNone,
RowLength: 0,
FieldSep: ",",
HeaderDefineChar: ":",
RunDelay: 0,
ConcurrentReqs: -1,
SourcePath: "/var/spool/cgrates/ers/in",
ProcessedPath: "/var/spool/cgrates/ers/out",
Filters: []string{},
Opts: make(map[string]interface{}),
},
{
ID: utils.MetaDefault,
Type: utils.MetaNone,
RowLength: 1,
FieldSep: ",",
HeaderDefineChar: ":",
RunDelay: 0,
ConcurrentReqs: -1,
SourcePath: "/var/spool/cgrates/ers/in",
ProcessedPath: "/var/spool/cgrates/ers/out",
Filters: []string{},
Opts: make(map[string]interface{}),
},
}
rdr, err := NewS3ER(cfg, 1, nil,
nil, nil, nil)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(rdr, expected) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, rdr)
}
}
func TestNewS3ERCase2(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
expected := &S3ER{
cgrCfg: cfg,
cfgIdx: 0,
cap: nil,
queueID: "cgrates_cdrs",
}
cfg.ERsCfg().Readers = []*config.EventReaderCfg{
{
ID: utils.MetaDefault,
Type: utils.MetaNone,
RowLength: 0,
FieldSep: ",",
HeaderDefineChar: ":",
RunDelay: 0,
ConcurrentReqs: 1,
SourcePath: "/var/spool/cgrates/ers/in",
ProcessedPath: "/var/spool/cgrates/ers/out",
Filters: []string{},
Opts: make(map[string]interface{}),
},
}
rdr, err := NewS3ER(cfg, 0, nil,
nil, nil, nil)
if err != nil {
t.Fatal(err)
}
expected.cap = rdr.(*S3ER).cap
if !reflect.DeepEqual(rdr, expected) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, rdr)
}
}