diff --git a/utils/cgrrecordwriter.go b/utils/cgrrecordwriter.go index 0a01552c4..3bb083a8c 100644 --- a/utils/cgrrecordwriter.go +++ b/utils/cgrrecordwriter.go @@ -22,7 +22,7 @@ import ( "io" ) -// Writer for one line, compatible with csv.Writer interface on Write +// CgrRecordWriter is a writer for one line, compatible with csv.Writer interface on Write // Used in TP exporter type CgrRecordWriter interface { Write([]string) error @@ -39,6 +39,7 @@ type CgrIORecordWriter struct { w io.Writer } +// Write into the Writer the record func (rw *CgrIORecordWriter) Write(record []string) error { for _, fld := range append(record, "\n") { // Postpend the new line char and write record in the writer if _, err := io.WriteString(rw.w, fld); err != nil { @@ -48,6 +49,7 @@ func (rw *CgrIORecordWriter) Write(record []string) error { return nil } +// Flush only to implement CgrRecordWriter // ToDo: make sure we properly handle this method func (*CgrIORecordWriter) Flush() { return diff --git a/utils/coreutils.go b/utils/coreutils.go index 450404daa..f5f1fe242 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -69,10 +69,13 @@ func init() { startCGRateSTime = time.Now() } +/* func GetTimeElapsedFromStart() string { return time.Now().Sub(startCGRateSTime).Round(time.Second).String() } +*/ +// GetStartTime return the Start time of engine (in UNIX format) func GetStartTime() string { return startCGRateSTime.Format(time.UnixDate) } @@ -112,7 +115,7 @@ func FirstNonEmpty(vals ...string) string { return val } } - return "" + return EmptyString } func Sha1(attrs ...string) string { diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go index 3657d9d1b..98015d949 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -25,7 +25,22 @@ import ( "time" ) +func TestGetStartTime(t *testing.T) { + startCGRateSTime = time.Date(2020, time.April, 18, 23, 0, 0, 0, time.UTC) + eOut := startCGRateSTime.Format(time.UnixDate) + rcv := GetStartTime() + if !reflect.DeepEqual(eOut, rcv) { + t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) + } +} + func TestFirstNonEmpty(t *testing.T) { + //only check with an empty string + rcv := FirstNonEmpty(EmptyString) + if rcv != EmptyString { + t.Errorf("Expecting an empty string, received: %+v", rcv) + } + //normal check firstElmnt := "" sampleMap := make(map[string]string) sampleMap["Third"] = "third"