/* 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 */ package engine import ( "testing" "time" "github.com/cgrates/cgrates/utils" ) func TestMsgpackStructsAdded(t *testing.T) { var a = struct{ First string }{"test"} var b = struct { First string Second string }{} m := utils.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 := utils.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 := utils.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 }