mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Fixup SM parse time bug discovered by DigiDaz, adding some more tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Rating system designed to be used in VoIP Carriers World
|
||||
Rating system for Telecom Environments
|
||||
Copyright (C) 2012-2014 ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can Storagetribute it and/or modify
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/*
|
||||
Rating system designed to be used in VoIP Carriers World
|
||||
Copyright (C) 2013 ITsysCOM
|
||||
Real-Time Charging System for Telecom Environments
|
||||
Copyright (C) 2012-2014 ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
This program is free software: you can Storagetribute 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
|
||||
but WITH*out ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ func (fsev FSEvent) MissingParameter() bool {
|
||||
}
|
||||
func (fsev FSEvent) GetSetupTime(fieldName string) (t time.Time, err error) {
|
||||
fsSTimeStr, hasKey := fsev[SETUP_TIME]
|
||||
if hasKey {
|
||||
if hasKey && fsSTimeStr != "0" {
|
||||
// Discard the nanoseconds information since MySQL cannot store them in early versions and csv uses default seconds so cgrid will not corelate
|
||||
fsSTimeStr = fsSTimeStr[:len(fsSTimeStr)-6]
|
||||
}
|
||||
@@ -163,7 +163,7 @@ func (fsev FSEvent) GetSetupTime(fieldName string) (t time.Time, err error) {
|
||||
}
|
||||
func (fsev FSEvent) GetAnswerTime(fieldName string) (t time.Time, err error) {
|
||||
fsATimeStr, hasKey := fsev[ANSWER_TIME]
|
||||
if hasKey {
|
||||
if hasKey && fsATimeStr != "0" {
|
||||
// Discard the nanoseconds information since MySQL cannot store them in early versions and csv uses default seconds so cgrid will not corelate
|
||||
fsATimeStr = fsATimeStr[:len(fsATimeStr)-6]
|
||||
}
|
||||
|
||||
@@ -130,3 +130,26 @@ Task-Runtime: 1349437318`
|
||||
dur != time.Duration(65)*time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDDazEmptyTime(t *testing.T) {
|
||||
body := `Event-Name: RE_SCHEDULE
|
||||
Core-UUID: 792e181c-b6e6-499c-82a1-52a778e7d82d
|
||||
FreeSWITCH-Hostname: h1.ip-switch.net
|
||||
FreeSWITCH-Switchname: h1.ip-switch.net
|
||||
FreeSWITCH-IPv4: 88.198.12.156
|
||||
Caller-Channel-Created-Time: 0
|
||||
Caller-Channel-Answered-Time
|
||||
Task-Runtime: 1349437318`
|
||||
var nilTime time.Time
|
||||
ev := new(FSEvent).New(body)
|
||||
if setupTime, err := ev.GetSetupTime(""); err != nil {
|
||||
t.Error("Error when parsing empty setupTime")
|
||||
} else if setupTime != nilTime {
|
||||
t.Error("Expecting nil time, got: ", setupTime)
|
||||
}
|
||||
if answerTime, err := ev.GetAnswerTime(""); err != nil {
|
||||
t.Error("Error when parsing empty setupTime")
|
||||
} else if answerTime != nilTime {
|
||||
t.Error("Expecting nil time, got: ", answerTime)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user