Example #1
0
func newTestCorpusWithPermanode() (*index.Corpus, blob.Ref) {
	c := index.ExpNewCorpus()
	pn := blob.MustParse("abc-123")
	tm := time.Unix(99, 0)
	claim := func(verb, attr, val string) *camtypes.Claim {
		tm = tm.Add(time.Second)
		return &camtypes.Claim{
			Type:  verb + "-attribute",
			Attr:  attr,
			Value: val,
			Date:  tm,
		}
	}

	c.SetClaims(pn, []*camtypes.Claim{
		claim("set", "foo", "foov"), // time 100

		claim("add", "tag", "a"), // time 101
		claim("add", "tag", "b"), // time 102
		claim("del", "tag", ""),
		claim("add", "tag", "c"),
		claim("add", "tag", "d"),
		claim("add", "tag", "e"),
		claim("del", "tag", "d"),

		claim("add", "DelAll", "a"),
		claim("add", "DelAll", "b"),
		claim("add", "DelAll", "c"),
		claim("del", "DelAll", ""),

		claim("add", "DelOne", "a"),
		claim("add", "DelOne", "b"),
		claim("add", "DelOne", "c"),
		claim("add", "DelOne", "d"),
		claim("del", "DelOne", "d"),
		claim("del", "DelOne", "a"),

		claim("add", "SetAfterAdd", "a"),
		claim("add", "SetAfterAdd", "b"),
		claim("set", "SetAfterAdd", "setv"),

		// add an element with fixed time to test
		// slow and fast path equivalence
		// (lookups based on pm.Claims and pm.Attrs, respectively)
		{
			Type:  "set-attribute",
			Attr:  "CacheTest",
			Value: "foo",
			Date:  time.Unix(201, 0),
		},
	})

	return c, pn
}
Example #2
0
func TestMergeFileInfoRow(t *testing.T) {
	c := index.ExpNewCorpus()
	c.Exp_mergeFileInfoRow("fileinfo|sha1-579f7f246bd420d486ddeb0dadbb256cfaf8bf6b",
		"100|something%2egif|image%2Fgif")
	fi := c.Exp_files(blob.MustParse("sha1-579f7f246bd420d486ddeb0dadbb256cfaf8bf6b"))
	want := camtypes.FileInfo{
		Size:     100,
		MIMEType: "image/gif",
		FileName: "something.gif",
	}
	if !reflect.DeepEqual(want, fi) {
		t.Errorf("Got %+v; want %+v", fi, want)
	}
}
Example #3
0
func testMergeFileInfoRow(t *testing.T, wholeRef string) {
	c := index.ExpNewCorpus()
	value := "100|something%2egif|image%2Fgif"
	want := camtypes.FileInfo{
		Size:     100,
		MIMEType: "image/gif",
		FileName: "something.gif",
	}
	if wholeRef != "" {
		value += "|" + wholeRef
		want.WholeRef = blob.MustParse(wholeRef)
	}
	c.Exp_mergeFileInfoRow("fileinfo|sha1-579f7f246bd420d486ddeb0dadbb256cfaf8bf6b", value)
	fi := c.Exp_files(blob.MustParse("sha1-579f7f246bd420d486ddeb0dadbb256cfaf8bf6b"))
	if !reflect.DeepEqual(want, fi) {
		t.Errorf("Got %+v; want %+v", fi, want)
	}
}
Example #4
0
func newTestCorpusWithPermanode() (c *index.Corpus, pn, sig1, sig2 blob.Ref) {
	c = index.ExpNewCorpus()
	pn = blob.MustParse("abc-123")
	sig1 = blob.MustParse("abc-456")
	sig2 = blob.MustParse("abc-789")
	tm := time.Unix(99, 0)
	claim := func(verb, attr, val string, sig blob.Ref) *camtypes.Claim {
		tm = tm.Add(time.Second)
		return &camtypes.Claim{
			Type:   verb + "-attribute",
			Attr:   attr,
			Value:  val,
			Date:   tm,
			Signer: sig,
		}
	}

	c.SetClaims(pn, []*camtypes.Claim{
		claim("set", "foo", "foov", sig1), // time 100

		claim("add", "tag", "a", sig1), // time 101
		claim("add", "tag", "b", sig1), // time 102
		claim("del", "tag", "", sig1),
		claim("add", "tag", "c", sig1),
		claim("add", "tag", "d", sig2),
		claim("add", "tag", "e", sig1),
		claim("del", "tag", "d", sig2),
		claim("add", "tag", "f", sig2),

		claim("add", "DelAll", "a", sig1),
		claim("add", "DelAll", "b", sig1),
		claim("add", "DelAll", "c", sig2),
		claim("del", "DelAll", "", sig1),

		claim("add", "DelOne", "a", sig1),
		claim("add", "DelOne", "b", sig1),
		claim("add", "DelOne", "c", sig1),
		claim("add", "DelOne", "d", sig2),
		claim("add", "DelOne", "e", sig2),
		claim("del", "DelOne", "d", sig2),
		claim("del", "DelOne", "a", sig1),

		claim("add", "SetAfterAdd", "a", sig1),
		claim("add", "SetAfterAdd", "b", sig1),
		claim("add", "SetAfterAdd", "c", sig2),
		claim("set", "SetAfterAdd", "setv", sig1),

		// The claims below help testing
		// slow and fast path equivalence
		// (lookups based on pm.Claims and cached attrs).
		//
		// Permanode attr queries at time.Time{} and
		// time.Unix(200, 0) should yield the same results
		// for the above claims. The difference is that
		// they use the cache at time.Time{} and
		// the pm.Claims directly (bypassing the cache)
		// at time.Unix(200, 0).
		{
			Type:   "set-attribute",
			Attr:   "CacheTest",
			Value:  "foo",
			Date:   time.Unix(201, 0),
			Signer: sig1,
		},
		{
			Type:   "set-attribute",
			Attr:   "CacheTest",
			Value:  "foo",
			Date:   time.Unix(202, 0),
			Signer: sig2,
		},
	})

	return c, pn, sig1, sig2
}
Example #5
0
func TestCorpusAppendPermanodeAttrValues(t *testing.T) {
	c := index.ExpNewCorpus()
	pn := blob.MustParse("abc-123")
	tm := time.Unix(99, 0)
	claim := func(verb, attr, val string) *camtypes.Claim {
		tm = tm.Add(time.Second)
		return &camtypes.Claim{
			Type:  verb + "-attribute",
			Attr:  attr,
			Value: val,
			Date:  tm,
		}
	}
	s := func(s ...string) []string { return s }

	c.SetClaims(pn, &index.PermanodeMeta{
		Claims: []*camtypes.Claim{
			claim("set", "foo", "foov"), // time 100

			claim("add", "tag", "a"), // time 101
			claim("add", "tag", "b"), // time 102
			claim("del", "tag", ""),
			claim("add", "tag", "c"),
			claim("add", "tag", "d"),
			claim("add", "tag", "e"),
			claim("del", "tag", "d"),

			claim("add", "DelAll", "a"),
			claim("add", "DelAll", "b"),
			claim("add", "DelAll", "c"),
			claim("del", "DelAll", ""),

			claim("add", "DelOne", "a"),
			claim("add", "DelOne", "b"),
			claim("add", "DelOne", "c"),
			claim("add", "DelOne", "d"),
			claim("del", "DelOne", "d"),
			claim("del", "DelOne", "a"),

			claim("add", "SetAfterAdd", "a"),
			claim("add", "SetAfterAdd", "b"),
			claim("set", "SetAfterAdd", "setv"),
		},
	})

	tests := []struct {
		attr string
		want []string
		t    time.Time
	}{
		{attr: "not-exist", want: s()},
		{attr: "DelAll", want: s()},
		{attr: "DelOne", want: s("b", "c")},
		{attr: "foo", want: s("foov")},
		{attr: "tag", want: s("c", "e")},
		{attr: "tag", want: s("a", "b"), t: time.Unix(102, 0)},
		{attr: "SetAfterAdd", want: s("setv")},
	}
	for i, tt := range tests {
		got := c.AppendPermanodeAttrValues(nil, pn, tt.attr, tt.t, blob.Ref{})
		if len(got) == 0 && len(tt.want) == 0 {
			continue
		}
		if !reflect.DeepEqual(got, tt.want) {
			t.Errorf("%d. attr %q = %q; want %q",
				i, tt.attr, got, tt.want)
		}
	}

}