mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
CastFieldIfToString with time.Duration support for acd/tcd
This commit is contained in:
@@ -50,6 +50,9 @@ func CastFieldIfToString(fld interface{}) (string, bool) {
|
||||
if byteVal, converted = fld.([]byte); converted {
|
||||
strVal = string(byteVal)
|
||||
}
|
||||
case time.Duration:
|
||||
strVal = fld.(time.Duration).String()
|
||||
converted = true
|
||||
default: // Maybe we are lucky and the value converts to string
|
||||
strVal, converted = fld.(string)
|
||||
}
|
||||
|
||||
@@ -216,3 +216,11 @@ func TestStringToInterface(t *testing.T) {
|
||||
t.Error("not parsing time.Duration")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCastFieldIfToString(t *testing.T) {
|
||||
if strVal, cast := CastFieldIfToString(time.Duration(1 * time.Second)); !cast {
|
||||
t.Error("cannot cast time.Duration")
|
||||
} else if strVal != "1s" {
|
||||
t.Errorf("received: %s", strVal)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user