Test OptAsString func in utils/cgrevent.go

This commit is contained in:
ionutboangiu
2021-03-05 11:05:29 +02:00
committed by Dan Christian Bogos
parent ee642fcc1a
commit cb96219bcd

View File

@@ -19,6 +19,7 @@ package utils
import (
"reflect"
"strconv"
"strings"
"testing"
"time"
@@ -435,3 +436,37 @@ func TestCGREventWithOptsCache(t *testing.T) {
}
event.CacheClear()
}
func TestCGREventOptAsStringEmpty(t *testing.T) {
ev := &CGREvent{}
expstr := ""
experr := ErrNotFound
received, err := ev.OptAsString("testString")
if !reflect.DeepEqual(received, expstr) {
t.Errorf("\nReceived: %q, \nExpected: %q", received, expstr)
}
if err == nil || err != experr {
t.Errorf("\nReceived: %q, \nExpected: %q", err, experr)
}
}
func TestCGREventOptAsString(t *testing.T) {
ev := &CGREvent{
Opts: map[string]interface{}{
"testKey": 13,
},
}
received, err := ev.OptAsString("testKey")
if err != nil {
t.Errorf("\nReceived: <%+v>, \nExpected: <%+v>", err, nil)
}
expected := strconv.Itoa(13)
if received != expected {
t.Errorf("\nReceived: %q, \nExpected: %q", received, expected)
}
}