1
0

Added test for structs within structs

This commit is contained in:
Patrick Mylund Nielsen 2012-01-29 04:35:47 +01:00
parent fdcb2f0aa6
commit 132462db11

View File

@ -6,6 +6,11 @@ import (
"time"
)
type TestStruct struct {
Num int
Children []*TestStruct
}
func TestCache(t *testing.T) {
tc := New(0, 0)
@ -97,10 +102,6 @@ func TestCacheTimes(t *testing.T) {
}
}
type TestStruct struct {
Num int
}
func TestStorePointerToStruct(t *testing.T) {
tc := New(0, 0)
tc.Set("foo", &TestStruct{Num: 1}, 0)
@ -474,6 +475,10 @@ func testFillAndSerialize(t *testing.T, tc *Cache) {
&TestStruct{Num: 4},
&TestStruct{Num: 5},
}, 0)
tc.Set("structception", &TestStruct{
Num: 42,
Children: []*TestStruct{&TestStruct{Num: 6174},},
}, 0)
tc.Set("c", "c", 0) // ordering should be meaningless, but just in case
fp := &bytes.Buffer{}
@ -549,6 +554,18 @@ func testFillAndSerialize(t *testing.T, tc *Cache) {
if s3r[1].Num != 5 {
t.Error("s3r[1].Num is not 5")
}
s4, found := oc.get("structception")
if !found {
t.Error("structception was not found")
}
s4r := s4.(*TestStruct)
if len(s4r.Children) != 1 {
t.Error("Length of s4r.Children is not 1")
}
if s4r.Children[0].Num != 6174 {
t.Error("s4r.Children[0].Num is not 6174")
}
}
func TestSerializeUnserializable(t *testing.T) {