Example #1
0
func TestAttrCache(t *testing.T) {
	os.Remove("/tmp/.zx")
	d := zx.Dir{"foo": "bar"}
	ac.set("/tmp/one", d)
	d = zx.Dir{"foo1": "bar1"}
	ac.set("/tmp/one", d)
	d = zx.Dir{"foo2": "bar2"}
	ac.set("/tmp/two", d)
	d = zx.Dir{}
	ac.get("/tmp/one", d)
	t.Logf("did get %s\n", d.LongFmt())
	if d.LongFmt() != `one foo:"bar" foo1:"bar1"` {
		t.Fatalf("didn't get attrs")
	}
	d = zx.Dir{}
	ac.get("/tmp/two", d)
	t.Logf("did get %s\n", d.LongFmt())
	if d.LongFmt() != `two foo2:"bar2"` {
		t.Fatalf("didn't get attrs")
	}
	ac.sync()
	d = zx.Dir{}
	ac.get("/tmp/one", d)
	t.Logf("did get %s\n", d.LongFmt())
	if d.LongFmt() != `one foo:"bar" foo1:"bar1"` {
		t.Fatalf("didn't get attrs after sync")
	}
	d = zx.Dir{"foo": "bar"}
	ac.set("/tmp/two", d)
	d = zx.Dir{}
	ac.get("/tmp/two", d)
	t.Logf("did get %s\n", d.LongFmt())
	if d.LongFmt() != `two foo:"bar" foo2:"bar2"` {
		t.Fatalf("didn't get attrs after sync")
	}
}