diff --git a/ers/libers_test.go b/ers/libers_test.go new file mode 100644 index 000000000..671b48aa8 --- /dev/null +++ b/ers/libers_test.go @@ -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 +*/ + +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) + } +} diff --git a/ers/s3_it_test.go b/ers/s3_it_test.go index 1ef083948..6830c7df8 100644 --- a/ers/s3_it_test.go +++ b/ers/s3_it_test.go @@ -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) + } +}