mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
More tests in utils
This commit is contained in:
committed by
Dan Christian Bogos
parent
56f9d16cc0
commit
dc3ae1bac6
@@ -913,13 +913,9 @@ func AESEncrypt(txt, encKey string) (encrypted string, err error) {
|
||||
return
|
||||
}
|
||||
var aesGCM cipher.AEAD
|
||||
if aesGCM, err = cipher.NewGCM(blk); err != nil {
|
||||
return
|
||||
}
|
||||
aesGCM, _ = cipher.NewGCM(blk)
|
||||
nonce := make([]byte, aesGCM.NonceSize())
|
||||
if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
|
||||
return
|
||||
}
|
||||
io.ReadFull(rand.Reader, nonce)
|
||||
return fmt.Sprintf("%x", aesGCM.Seal(nonce, nonce, []byte(txt), nil)), nil
|
||||
}
|
||||
|
||||
@@ -935,10 +931,7 @@ func AESDecrypt(encrypted string, encKey string) (txt string, err error) {
|
||||
}
|
||||
|
||||
var aesGCM cipher.AEAD
|
||||
if aesGCM, err = cipher.NewGCM(blk); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
aesGCM, _ = cipher.NewGCM(blk)
|
||||
nonceSize := aesGCM.NonceSize()
|
||||
nonce, ciphertext := enc[:nonceSize], enc[nonceSize:]
|
||||
var plaintext []byte
|
||||
|
||||
@@ -771,9 +771,24 @@ func TestNavMapGetFieldAsMapStringInterface(t *testing.T) {
|
||||
"Field2": "Val2"},
|
||||
}
|
||||
path := []string{"FIELD[Field2]"}
|
||||
result, _ := nM.FieldAsInterface(path)
|
||||
if reflect.DeepEqual(result, "val2") {
|
||||
t.Errorf("Expecting: <val2>, received: %+v", result)
|
||||
if result, err := nM.FieldAsInterface(path); err != nil {
|
||||
t.Errorf("Expecting: <nil>, received: %+v", err)
|
||||
} else if !reflect.DeepEqual(result, "Val2") {
|
||||
t.Errorf("Expecting: <Val2>, received: %+v", result)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNavMapGetFieldAsDataProvider(t *testing.T) {
|
||||
nM := MapStorage{
|
||||
"FIELD": MapStorage{
|
||||
"Field1": "Val1",
|
||||
"Field2": "Val2"},
|
||||
}
|
||||
path := []string{"FIELD[Field2]"}
|
||||
if result, err := nM.FieldAsInterface(path); err != nil {
|
||||
t.Errorf("Expecting: <nil>, received: %+v", err)
|
||||
} else if !reflect.DeepEqual(result, "Val2") {
|
||||
t.Errorf("Expecting: <Val2>, received: %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
@@ -31,11 +32,11 @@ type Attr struct {
|
||||
Age float64
|
||||
}
|
||||
|
||||
func (rpc *RpcStruct) Hopa(normal Attr, out *float64) error {
|
||||
func (rpc *RpcStruct) Method1(normal Attr, out *float64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rpc *RpcStruct) Tropa(pointer *Attr, out *float64) error {
|
||||
func (rpc *RpcStruct) Method2(pointer *Attr, out *float64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ func TestRPCObjectPointer(t *testing.T) {
|
||||
if len(rpcParamsMap) != 2 {
|
||||
t.Errorf("error registering rpc object: %v", rpcParamsMap)
|
||||
}
|
||||
x, found := rpcParamsMap["RpcStruct.Hopa"]
|
||||
x, found := rpcParamsMap["RpcStruct.Method1"]
|
||||
if !found {
|
||||
t.Errorf("error getting rpcobject: %v (%+v)", rpcParamsMap, x)
|
||||
}
|
||||
@@ -56,18 +57,6 @@ func TestRPCObjectPointer(t *testing.T) {
|
||||
if err := mapstructure.Decode(map[string]interface{}{"Name": "a", "Surname": "b", "Age": 10.2}, a); err != nil || a.(*Attr).Name != "a" || a.(*Attr).Surname != "b" || a.(*Attr).Age != 10.2 {
|
||||
t.Errorf("error converting to struct: %+v (%v)", a, err)
|
||||
}
|
||||
/*
|
||||
//TODO: make pointer in arguments usable
|
||||
x, found = rpcParamsMap["RpcStruct.Tropa"]
|
||||
if !found {
|
||||
t.Errorf("error getting rpcobject: %v (%+v)", rpcParamsMap, x)
|
||||
}
|
||||
b := x.InParam
|
||||
// log.Printf("T: %+v", b)
|
||||
if err := mapstructure.Decode(map[string]interface{}{"Name": "a", "Surname": "b", "Age": 10.2}, b); err != nil || b.(*Attr).Name != "a" || b.(*Attr).Surname != "b" || b.(*Attr).Age != 10.2 {
|
||||
t.Errorf("error converting to struct: %+v (%v)", b, err)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func TestGetRpcParamsError(t *testing.T) {
|
||||
@@ -76,3 +65,13 @@ func TestGetRpcParamsError(t *testing.T) {
|
||||
t.Errorf("Expected <NOT_FOUND>, received <%+v>", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRpcParams(t *testing.T) {
|
||||
testStruct := &Attr{"", "", 0}
|
||||
RegisterRpcParams("", &RpcStruct{})
|
||||
if result, err := GetRpcParams("RpcStruct.Method1"); err != nil {
|
||||
t.Errorf("Expected <nil>, received <%+v>", err)
|
||||
} else if !reflect.DeepEqual(result.InParam, testStruct) {
|
||||
t.Errorf("Expected <%+v>, received <%+v>", testStruct, result.InParam)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,3 +429,47 @@ func TestParseRSRFiltersFromSliceError(t *testing.T) {
|
||||
t.Errorf("Expected <error parsing regexp: missing closing ): `(^_^`> ,received: <%+v>", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRFilterPassMatchGreaterThanOrEqual(t *testing.T) {
|
||||
fltr, err := NewRSRFilter(">=0")
|
||||
if err != nil {
|
||||
t.Errorf("Expected <nil> ,received: <%+v>", err)
|
||||
}
|
||||
result := fltr.Pass("string")
|
||||
if !reflect.DeepEqual(false, result) {
|
||||
t.Errorf("Expected <false> ,received: <%+v>", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRFilterPassMatchLessThanOrEqual(t *testing.T) {
|
||||
fltr, err := NewRSRFilter("<=0")
|
||||
if err != nil {
|
||||
t.Errorf("Expected <nil> ,received: <%+v>", err)
|
||||
}
|
||||
result := fltr.Pass("string")
|
||||
if !reflect.DeepEqual(false, result) {
|
||||
t.Errorf("Expected <false> ,received: <%+v>", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRFilterPassMatchGreaterThan(t *testing.T) {
|
||||
fltr, err := NewRSRFilter(">0")
|
||||
if err != nil {
|
||||
t.Errorf("Expected <nil> ,received: <%+v>", err)
|
||||
}
|
||||
result := fltr.Pass("invalid")
|
||||
if !reflect.DeepEqual(false, result) {
|
||||
t.Errorf("Expected <false> ,received: <%+v>", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSRFilterPassMatchLessThan(t *testing.T) {
|
||||
fltr, err := NewRSRFilter("<0")
|
||||
if err != nil {
|
||||
t.Errorf("Expected <nil> ,received: <%+v>", err)
|
||||
}
|
||||
result := fltr.Pass("string")
|
||||
if !reflect.DeepEqual(false, result) {
|
||||
t.Errorf("Expected <false> ,received: <%+v>", result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user