mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 20:59:53 +05:00
FieldSeparator as string instead of rune inside ExportCdrs API
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user