mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
/*
|
|
Real-time Online/Offline Charging System (OCS) 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 engine
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestMsgpackStructsAdded(t *testing.T) {
|
|
var a = struct{ First string }{"test"}
|
|
var b = struct {
|
|
First string
|
|
Second string
|
|
}{}
|
|
m := NewCodecMsgpackMarshaler()
|
|
buf, err := m.Marshal(&a)
|
|
if err != nil {
|
|
t.Error("error marshaling structure: ", err)
|
|
}
|
|
err = m.Unmarshal(buf, &b)
|
|
if err != nil || b.First != "test" || b.Second != "" {
|
|
t.Error("error unmarshalling structure: ", b, err)
|
|
}
|
|
}
|
|
|
|
func TestMsgpackStructsMissing(t *testing.T) {
|
|
var a = struct {
|
|
First string
|
|
Second string
|
|
}{"test1", "test2"}
|
|
var b = struct{ First string }{}
|
|
m := NewCodecMsgpackMarshaler()
|
|
buf, err := m.Marshal(&a)
|
|
if err != nil {
|
|
t.Error("error marshaling structure: ", err)
|
|
}
|
|
err = m.Unmarshal(buf, &b)
|
|
if err != nil || b.First != "test1" {
|
|
t.Error("error unmarshalling structure: ", b, err)
|
|
}
|
|
}
|
|
|
|
func TestMsgpackTime(t *testing.T) {
|
|
t1 := time.Date(2013, 8, 28, 22, 27, 30, 11, time.UTC)
|
|
m := NewCodecMsgpackMarshaler()
|
|
buf, err := m.Marshal(&t1)
|
|
if err != nil {
|
|
t.Error("error marshaling structure: ", err)
|
|
}
|
|
var t2 time.Time
|
|
err = m.Unmarshal(buf, &t2)
|
|
if err != nil || t1 != t2 || !t1.Equal(t2) {
|
|
t.Errorf("error unmarshalling structure: %#v %#v %v", t1, t2, err)
|
|
}
|
|
}
|
|
|
|
// Install fails to detect them and starting server will panic, these tests will fix this
|
|
func TestStoreInterfaces(t *testing.T) {
|
|
rds := new(RedisStorage)
|
|
var _ DataDB = rds
|
|
sql := new(SQLStorage)
|
|
var _ CdrStorage = sql
|
|
}
|