MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / TestFileSerialization

Function TestFileSerialization

pkg/util/cache/cache_test.go:1393–1430  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1391}
1392
1393func TestFileSerialization(t *testing.T) {
1394 tc := New(DefaultExpiration, 0)
1395 tc.Add("a", "a", DefaultExpiration)
1396 tc.Add("b", "b", DefaultExpiration)
1397 f, err := ioutil.TempFile("", "go-cache-cache.dat")
1398 if err != nil {
1399 t.Fatal("Couldn't create cache file:", err)
1400 }
1401 fname := f.Name()
1402 f.Close()
1403 tc.SaveFile(fname)
1404
1405 oc := New(DefaultExpiration, 0)
1406 oc.Add("a", "aa", 0) // this should not be overwritten
1407 err = oc.LoadFile(fname)
1408 if err != nil {
1409 t.Error(err)
1410 }
1411 a, found := oc.Get("a")
1412 if !found {
1413 t.Error("a was not found")
1414 }
1415 astr := a.(string)
1416 if astr != "aa" {
1417 if astr == "a" {
1418 t.Error("a was overwritten")
1419 } else {
1420 t.Error("a is not aa")
1421 }
1422 }
1423 b, found := oc.Get("b")
1424 if !found {
1425 t.Error("b was not found")
1426 }
1427 if b.(string) != "b" {
1428 t.Error("b is not b")
1429 }
1430}
1431
1432func TestSerializeUnserializable(t *testing.T) {
1433 tc := New(DefaultExpiration, 0)

Callers

nothing calls this directly

Calls 8

SaveFileMethod · 0.80
LoadFileMethod · 0.80
NewFunction · 0.70
NameMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65
AddMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected