Updated tests in utils

This commit is contained in:
adragusin
2019-11-18 17:56:08 +02:00
committed by Dan Christian Bogos
parent 6e7715be85
commit cb61c179b0
3 changed files with 22 additions and 2 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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"