mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated tests in utils
This commit is contained in:
committed by
Dan Christian Bogos
parent
6e7715be85
commit
cb61c179b0
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user