FieldSeparator as string instead of rune inside ExportCdrs API

This commit is contained in:
DanB
2014-09-23 12:21:02 +02:00
parent a67def57b9
commit 134f0ead17
4 changed files with 29 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"
"github.com/cgrates/cgrates/cdre"
"github.com/cgrates/cgrates/config"
@@ -117,8 +118,11 @@ func (self *ApierV1) ExportCdrsToFile(attr utils.AttrExpFileCdrs, reply *utils.E
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "CdrFormat")
}
fieldSep := exportTemplate.FieldSeparator
if attr.FieldSeparator != nil {
fieldSep = *attr.FieldSeparator
if attr.FieldSeparator != nil && len(*attr.FieldSeparator) != 0 {
fieldSep, _ = utf8.DecodeRuneInString(*attr.FieldSeparator)
if fieldSep == utf8.RuneError {
return fmt.Errorf("%s:FieldSeparator:%s", utils.ERR_SERVER_ERROR, "Invalid")
}
}
exportDir := exportTemplate.ExportDir
if attr.ExportDir != nil && len(*attr.ExportDir) != 0 {

View File

@@ -517,7 +517,7 @@ type CachedItemAge struct {
type AttrExpFileCdrs struct {
CdrFormat *string // Cdr output file format <utils.CdreCdrFormats>
FieldSeparator *rune // Separator used between fields
FieldSeparator *string // Separator used between fields
ExportId *string // Optional exportid
ExportDir *string // If provided it overwrites the configured export directory
ExportFileName *string // If provided the output filename will be set to this

View File

@@ -232,6 +232,14 @@ func TestFormatUsage(t *testing.T) {
if cdr.FormatUsage("default") != "1640113" {
t.Error("Wrong usage format: ", cdr.FormatUsage("default"))
}
cdr = StoredCdr{Usage: time.Duration(2) * time.Millisecond}
if cdr.FormatUsage("default") != "0.002" {
t.Error("Wrong usage format: ", cdr.FormatUsage("default"))
}
cdr = StoredCdr{Usage: time.Duration(1002) * time.Millisecond}
if cdr.FormatUsage("default") != "1.002" {
t.Error("Wrong usage format: ", cdr.FormatUsage("default"))
}
}
func TestStoredCdrAsHttpForm(t *testing.T) {

View File

@@ -389,6 +389,20 @@ func TestParseDurationWithSecs(t *testing.T) {
} else if parsed != durExpected {
t.Error("Parsed different than expected")
}
durStr = "0.002"
durExpected = time.Duration(2) * time.Millisecond
if parsed, err := ParseDurationWithSecs(durStr); err != nil {
t.Error(err)
} else if parsed != durExpected {
t.Error("Parsed different than expected")
}
durStr = "1.002"
durExpected = time.Duration(1002) * time.Millisecond
if parsed, err := ParseDurationWithSecs(durStr); err != nil {
t.Error(err)
} else if parsed != durExpected {
t.Error("Parsed different than expected")
}
}
func TestMinDuration(t *testing.T) {