Files
cgrates/utils/reflect_test.go

74 lines
2.3 KiB
Go

/*
Real-time Charging System for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package utils
import (
"testing"
)
func TestReflectFieldAsString(t *testing.T) {
mystruct := struct {
Title string
Count int
Count64 int64
Val float64
ExtraFields map[string]interface{}
}{"Title1", 5, 6, 7.3, map[string]interface{}{"a": "Title2", "b": 15, "c": int64(16), "d": 17.3}}
if strVal, err := ReflectFieldAsString(mystruct, "Title", "ExtraFields"); err != nil {
t.Error(err)
} else if strVal != "Title1" {
t.Error("Received: %s", strVal)
}
if strVal, err := ReflectFieldAsString(mystruct, "Count", "ExtraFields"); err != nil {
t.Error(err)
} else if strVal != "5" {
t.Error("Received: %s", strVal)
}
if strVal, err := ReflectFieldAsString(mystruct, "Count64", "ExtraFields"); err != nil {
t.Error(err)
} else if strVal != "6" {
t.Error("Received: %s", strVal)
}
if strVal, err := ReflectFieldAsString(mystruct, "Val", "ExtraFields"); err != nil {
t.Error(err)
} else if strVal != "7.3" {
t.Error("Received: %s", strVal)
}
if strVal, err := ReflectFieldAsString(mystruct, "a", "ExtraFields"); err != nil {
t.Error(err)
} else if strVal != "Title2" {
t.Error("Received: %s", strVal)
}
if strVal, err := ReflectFieldAsString(mystruct, "b", "ExtraFields"); err != nil {
t.Error(err)
} else if strVal != "15" {
t.Error("Received: %s", strVal)
}
if strVal, err := ReflectFieldAsString(mystruct, "c", "ExtraFields"); err != nil {
t.Error(err)
} else if strVal != "16" {
t.Error("Received: %s", strVal)
}
if strVal, err := ReflectFieldAsString(mystruct, "d", "ExtraFields"); err != nil {
t.Error(err)
} else if strVal != "17.3" {
t.Error("Received: %s", strVal)
}
}